Skip to content

Commit 3fd56db

Browse files
committed
Support endpoints for handling search synonyms
1 parent a77c544 commit 3fd56db

17 files changed

+800
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The client is available in the [Maven Central Repository](https://mvnrepository.
1313
<dependency>
1414
<groupId>com.recombee</groupId>
1515
<artifactId>api-client</artifactId>
16-
<version>3.1.0</version>
16+
<version>3.2.0</version>
1717
</dependency>
1818
```
1919

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.recombee</groupId>
88
<artifactId>api-client</artifactId>
9-
<version>3.1.0</version>
9+
<version>3.2.0</version>
1010
<name>Recombee API Client</name>
1111
<description>A client library for easy use of the Recombee recommendation API</description>
1212
<url>http://recombee.com</url>

src/main/java/com/recombee/api_client/RecombeeClient.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@
6969
import com.recombee.api_client.api_requests.RecommendNextItems;
7070
import com.recombee.api_client.api_requests.RecommendUsersToUser;
7171
import com.recombee.api_client.api_requests.RecommendUsersToItem;
72-
import com.recombee.api_client.api_requests.SearchItems;
7372
import com.recombee.api_client.api_requests.UserBasedRecommendation;
7473
import com.recombee.api_client.api_requests.ItemBasedRecommendation;
74+
import com.recombee.api_client.api_requests.SearchItems;
75+
import com.recombee.api_client.api_requests.AddSearchSynonym;
76+
import com.recombee.api_client.api_requests.ListSearchSynonyms;
7577

7678
/* End of the generated code */
7779
/**
@@ -88,7 +90,7 @@ public class RecombeeClient {
8890

8991
final int BATCH_MAX_SIZE = 10000; //Maximal number of requests within one batch request
9092

91-
final String USER_AGENT = "recombee-java-api-client/3.1.0";
93+
final String USER_AGENT = "recombee-java-api-client/3.2.0";
9294

9395
private final OkHttpClient httpClient = new OkHttpClient();
9496

@@ -378,6 +380,26 @@ public SearchResponse send(SearchItems request) throws ApiException {
378380
return null;
379381
}
380382

383+
public SearchSynonym send(AddSearchSynonym request) throws ApiException {
384+
String responseStr = sendRequest(request);
385+
try {
386+
return this.mapper.readValue(responseStr, SearchSynonym.class);
387+
} catch (IOException e) {
388+
e.printStackTrace();
389+
}
390+
return null;
391+
}
392+
393+
public ListSearchSynonymsResponse send(ListSearchSynonyms request) throws ApiException {
394+
String responseStr = sendRequest(request);
395+
try {
396+
return this.mapper.readValue(responseStr, ListSearchSynonymsResponse.class);
397+
} catch (IOException e) {
398+
e.printStackTrace();
399+
}
400+
return null;
401+
}
402+
381403
/* End of the generated code */
382404

383405
public BatchResponse[] send(Batch batchRequest) throws ApiException {
@@ -462,6 +484,14 @@ else if (request instanceof ListUsers)
462484
parsedResponse = ar;
463485
}
464486
}
487+
else if (request instanceof AddSearchSynonym)
488+
{
489+
parsedResponse = mapper.convertValue(parsedResponse, SearchSynonym.class);
490+
}
491+
else if (request instanceof ListSearchSynonyms)
492+
{
493+
parsedResponse = mapper.convertValue(parsedResponse, ListSearchSynonymsResponse.class);
494+
}
465495
else if ((request instanceof RecommendItemsToUser) ||
466496
(request instanceof RecommendUsersToUser) ||
467497
(request instanceof RecommendItemsToItem) ||
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.recombee.api_client.api_requests;
2+
3+
/*
4+
This file is auto-generated, do not edit
5+
*/
6+
7+
import java.util.Date;
8+
import java.util.Map;
9+
import java.util.HashMap;
10+
11+
import com.recombee.api_client.bindings.Logic;
12+
import com.recombee.api_client.util.HTTPMethod;
13+
14+
/**
15+
* Adds a new synonym for the [Search items](https://docs.recombee.com/api.html#search-items).
16+
* When the `term` is used in the search query, the `synonym` is also used for the full-text search.
17+
* Unless `oneWay=true`, it works also in the opposite way (`synonym` -> `term`).
18+
* An example of a synonym can be `science fiction` for the term `sci-fi`.
19+
*/
20+
public class AddSearchSynonym extends Request {
21+
22+
/**
23+
* A word to which the `synonym` is specified.
24+
*/
25+
protected String term;
26+
/**
27+
* A word that should be considered equal to the `term` by the full-text search engine.
28+
*/
29+
protected String synonym;
30+
/**
31+
* If set to `true`, only `term` -> `synonym` is considered. If set to `false`, also `synonym` -> `term` works.
32+
* Default: `false`.
33+
*/
34+
protected Boolean oneWay;
35+
36+
/**
37+
* Construct the request
38+
* @param term A word to which the `synonym` is specified.
39+
* @param synonym A word that should be considered equal to the `term` by the full-text search engine.
40+
*/
41+
public AddSearchSynonym (String term,String synonym) {
42+
this.term = term;
43+
this.synonym = synonym;
44+
this.timeout = 10000;
45+
}
46+
47+
/**
48+
* @param oneWay If set to `true`, only `term` -> `synonym` is considered. If set to `false`, also `synonym` -> `term` works.
49+
* Default: `false`.
50+
*/
51+
public AddSearchSynonym setOneWay(boolean oneWay) {
52+
this.oneWay = oneWay;
53+
return this;
54+
}
55+
56+
public String getTerm() {
57+
return this.term;
58+
}
59+
60+
public String getSynonym() {
61+
return this.synonym;
62+
}
63+
64+
public boolean getOneWay() {
65+
if (this.oneWay==null) return false;
66+
return this.oneWay;
67+
}
68+
69+
/**
70+
* @return Used HTTP method
71+
*/
72+
@Override
73+
public HTTPMethod getHTTPMethod() {
74+
return HTTPMethod.POST;
75+
}
76+
77+
/**
78+
* @return URI to the endpoint including path parameters
79+
*/
80+
@Override
81+
public String getPath() {
82+
return "/synonyms/items/";
83+
}
84+
85+
/**
86+
* Get query parameters
87+
* @return Values of query parameters (name of parameter: value of the parameter)
88+
*/
89+
@Override
90+
public Map<String, Object> getQueryParameters() {
91+
HashMap<String, Object> params = new HashMap<String, Object>();
92+
return params;
93+
}
94+
95+
/**
96+
* Get body parameters
97+
* @return Values of body parameters (name of parameter: value of the parameter)
98+
*/
99+
@Override
100+
public Map<String, Object> getBodyParameters() {
101+
HashMap<String, Object> params = new HashMap<String, Object>();
102+
params.put("term", this.term);
103+
params.put("synonym", this.synonym);
104+
if (this.oneWay!=null) {
105+
params.put("oneWay", this.oneWay);
106+
}
107+
return params;
108+
}
109+
110+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.recombee.api_client.api_requests;
2+
3+
/*
4+
This file is auto-generated, do not edit
5+
*/
6+
7+
import java.util.Date;
8+
import java.util.Map;
9+
import java.util.HashMap;
10+
11+
import com.recombee.api_client.bindings.Logic;
12+
import com.recombee.api_client.util.HTTPMethod;
13+
14+
/**
15+
* Deletes all synonyms defined in the database.
16+
*/
17+
public class DeleteAllSearchSynonyms extends Request {
18+
19+
20+
/**
21+
* Construct the request
22+
*/
23+
public DeleteAllSearchSynonyms () {
24+
this.timeout = 10000;
25+
}
26+
27+
28+
29+
/**
30+
* @return Used HTTP method
31+
*/
32+
@Override
33+
public HTTPMethod getHTTPMethod() {
34+
return HTTPMethod.DELETE;
35+
}
36+
37+
/**
38+
* @return URI to the endpoint including path parameters
39+
*/
40+
@Override
41+
public String getPath() {
42+
return "/synonyms/items/";
43+
}
44+
45+
/**
46+
* Get query parameters
47+
* @return Values of query parameters (name of parameter: value of the parameter)
48+
*/
49+
@Override
50+
public Map<String, Object> getQueryParameters() {
51+
HashMap<String, Object> params = new HashMap<String, Object>();
52+
return params;
53+
}
54+
55+
/**
56+
* Get body parameters
57+
* @return Values of body parameters (name of parameter: value of the parameter)
58+
*/
59+
@Override
60+
public Map<String, Object> getBodyParameters() {
61+
HashMap<String, Object> params = new HashMap<String, Object>();
62+
return params;
63+
}
64+
65+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.recombee.api_client.api_requests;
2+
3+
/*
4+
This file is auto-generated, do not edit
5+
*/
6+
7+
import java.util.Date;
8+
import java.util.Map;
9+
import java.util.HashMap;
10+
11+
import com.recombee.api_client.bindings.Logic;
12+
import com.recombee.api_client.util.HTTPMethod;
13+
14+
/**
15+
* Deletes synonym of given `id` and this synonym is no longer taken into account in the [Search items](https://docs.recombee.com/api.html#search-items).
16+
*/
17+
public class DeleteSearchSynonym extends Request {
18+
19+
/**
20+
* ID of the synonym that should be deleted.
21+
*/
22+
protected String id;
23+
24+
/**
25+
* Construct the request
26+
* @param id ID of the synonym that should be deleted.
27+
*/
28+
public DeleteSearchSynonym (String id) {
29+
this.id = id;
30+
this.timeout = 10000;
31+
}
32+
33+
34+
public String getId() {
35+
return this.id;
36+
}
37+
38+
/**
39+
* @return Used HTTP method
40+
*/
41+
@Override
42+
public HTTPMethod getHTTPMethod() {
43+
return HTTPMethod.DELETE;
44+
}
45+
46+
/**
47+
* @return URI to the endpoint including path parameters
48+
*/
49+
@Override
50+
public String getPath() {
51+
return String.format("/synonyms/items/%s", this.id);
52+
}
53+
54+
/**
55+
* Get query parameters
56+
* @return Values of query parameters (name of parameter: value of the parameter)
57+
*/
58+
@Override
59+
public Map<String, Object> getQueryParameters() {
60+
HashMap<String, Object> params = new HashMap<String, Object>();
61+
return params;
62+
}
63+
64+
/**
65+
* Get body parameters
66+
* @return Values of body parameters (name of parameter: value of the parameter)
67+
*/
68+
@Override
69+
public Map<String, Object> getBodyParameters() {
70+
HashMap<String, Object> params = new HashMap<String, Object>();
71+
return params;
72+
}
73+
74+
}

0 commit comments

Comments
 (0)