Skip to content

Commit 500d8e2

Browse files
committed
Release: v6.2.0
- Added recommend-next-item-segments endpoint support - Added `searchQuery` parameter support for composite recommendations
1 parent 1d34c95 commit 500d8e2

7 files changed

Lines changed: 216 additions & 5 deletions

File tree

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>6.1.0</version>
16+
<version>6.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>6.1.0</version>
9+
<version>6.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>https://www.recombee.com</url>

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import com.recombee.api_client.api_requests.RecommendItemSegmentsToUser;
7575
import com.recombee.api_client.api_requests.RecommendItemSegmentsToItem;
7676
import com.recombee.api_client.api_requests.RecommendItemSegmentsToItemSegment;
77+
import com.recombee.api_client.api_requests.RecommendNextItemSegments;
7778
import com.recombee.api_client.api_requests.CompositeRecommendation;
7879
import com.recombee.api_client.api_requests.SearchItems;
7980
import com.recombee.api_client.api_requests.SearchItemSegments;
@@ -98,7 +99,7 @@ public class RecombeeClient {
9899

99100
final int BATCH_MAX_SIZE = 10000; //Maximal number of requests within one batch request
100101

101-
final String USER_AGENT = "recombee-java-api-client/6.1.0";
102+
final String USER_AGENT = "recombee-java-api-client/6.2.0";
102103

103104
private final OkHttpClient httpClient = new OkHttpClient();
104105

@@ -444,6 +445,16 @@ public RecommendationResponse send(RecommendItemSegmentsToItemSegment request) t
444445
return null;
445446
}
446447

448+
public RecommendationResponse send(RecommendNextItemSegments request) throws ApiException {
449+
String responseStr = sendRequest(request);
450+
try {
451+
return this.mapper.readValue(responseStr, RecommendationResponse.class);
452+
} catch (IOException e) {
453+
e.printStackTrace();
454+
}
455+
return null;
456+
}
457+
447458
public CompositeRecommendationResponse send(CompositeRecommendation request) throws ApiException {
448459
String responseStr = sendRequest(request);
449460
try {
@@ -604,7 +615,8 @@ else if ((request instanceof RecommendItemsToUser) ||
604615
(request instanceof RecommendItemSegmentsToItem) ||
605616
(request instanceof RecommendItemsToItemSegment) ||
606617
(request instanceof RecommendItemSegmentsToItemSegment) ||
607-
(request instanceof SearchItemSegments))
618+
(request instanceof SearchItemSegments) ||
619+
(request instanceof RecommendNextItemSegments))
608620
{
609621
parsedResponse = mapper.convertValue(parsedResponse, RecommendationResponse.class);
610622
}

src/main/java/com/recombee/api_client/api_requests/CompositeRecommendation.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import com.recombee.api_client.util.HTTPMethod;
1414

1515
/**
16-
* Composite Recommendation returns both a *source entity* (e.g., an Item or [Item Segment](https://docs.recombee.com/segmentations.html)) and a list of related recommendations in a single response.
16+
* Composite Recommendation returns both a *source entity* (e.g., an Item or [Item Segment](https://docs.recombee.com/segmentations)) and a list of related recommendations in a single response.
1717
* It is ideal for use cases such as personalized homepage sections (*Articles from &lt;category&gt;*), *Because You Watched &lt;movie&gt;*, or *Artists Related to Your Favorite Artist &lt;artist&gt;*.
1818
* See detailed **examples and configuration guidance** in the [Composite Scenarios documentation](https://docs.recombee.com/scenarios#composite-recommendations).
1919
* **Structure**
@@ -63,6 +63,10 @@ public class CompositeRecommendation extends Request {
6363
* ID of the segment from `contextSegmentationId` for which the recommendations are to be generated.
6464
*/
6565
protected String segmentId;
66+
/**
67+
* Search query provided by the user. It is used for the full-text search. Only applicable if the *scenario* corresponds to a search scenario.
68+
*/
69+
protected String searchQuery;
6670
/**
6771
* If the entity for the source recommendation does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows, for example, rotations in the following recommendations for that entity, as the entity will be already known to the system.
6872
*/
@@ -128,6 +132,14 @@ public CompositeRecommendation setSegmentId(String segmentId) {
128132
return this;
129133
}
130134

135+
/**
136+
* @param searchQuery Search query provided by the user. It is used for the full-text search. Only applicable if the *scenario* corresponds to a search scenario.
137+
*/
138+
public CompositeRecommendation setSearchQuery(String searchQuery) {
139+
this.searchQuery = searchQuery;
140+
return this;
141+
}
142+
131143
/**
132144
* @param cascadeCreate If the entity for the source recommendation does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows, for example, rotations in the following recommendations for that entity, as the entity will be already known to the system.
133145
*/
@@ -184,6 +196,10 @@ public String getSegmentId() {
184196
return this.segmentId;
185197
}
186198

199+
public String getSearchQuery() {
200+
return this.searchQuery;
201+
}
202+
187203
public boolean getCascadeCreate() {
188204
if (this.cascadeCreate==null) return false;
189205
return this.cascadeCreate;
@@ -248,6 +264,9 @@ public Map<String, Object> getBodyParameters() {
248264
if (this.segmentId!=null) {
249265
params.put("segmentId", this.segmentId);
250266
}
267+
if (this.searchQuery!=null) {
268+
params.put("searchQuery", this.searchQuery);
269+
}
251270
if (this.cascadeCreate!=null) {
252271
params.put("cascadeCreate", this.cascadeCreate);
253272
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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.bindings.CompositeRecommendationStageParameters;
13+
import com.recombee.api_client.util.HTTPMethod;
14+
15+
/**
16+
* Returns Item segments that shall be shown to a user as next recommendations when the user e.g. scrolls the page down (*infinite scroll*) or goes to the next page.
17+
* It accepts `recommId` of a base recommendation request (e.g., request from the first page) and the number of segments that shall be returned (`count`).
18+
* The base request can be one of:
19+
* - [Recommend Item Segments to Item](https://docs.recombee.com/api#recommend-item-segments-to-item)
20+
* - [Recommend Item Segments to User](https://docs.recombee.com/api#recommend-item-segments-to-user)
21+
* - [Recommend Item Segments to Item Segment](https://docs.recombee.com/api#recommend-item-segments-to-item-segment)
22+
* - [Search Item Segments](https://docs.recombee.com/api#search-item-segments)
23+
* All the other parameters are inherited from the base request.
24+
* *Recommend next Item segments* can be called many times for a single `recommId` and each call returns different (previously not recommended) segments.
25+
* The number of *Recommend next Item segments* calls performed so far is returned in the `numberNextRecommsCalls` field.
26+
* *Recommend next Item segments* can be requested up to 30 minutes after the base request or a previous *Recommend next Item segments* call.
27+
* For billing purposes, each call to *Recommend next Item segments* is counted as a separate recommendation request.
28+
*/
29+
public class RecommendNextItemSegments extends Request {
30+
31+
/**
32+
* ID of the base recommendation request for which next recommendations should be returned
33+
*/
34+
protected String recommId;
35+
/**
36+
* Number of item segments to be recommended
37+
*/
38+
protected Long count;
39+
40+
/**
41+
* Construct the request
42+
* @param recommId ID of the base recommendation request for which next recommendations should be returned
43+
* @param count Number of item segments to be recommended
44+
*/
45+
public RecommendNextItemSegments (String recommId,long count) {
46+
this.recommId = recommId;
47+
this.count = count;
48+
this.timeout = 3000;
49+
}
50+
51+
52+
public String getRecommId() {
53+
return this.recommId;
54+
}
55+
56+
public long getCount() {
57+
return this.count;
58+
}
59+
60+
/**
61+
* @return Used HTTP method
62+
*/
63+
@Override
64+
public HTTPMethod getHTTPMethod() {
65+
return HTTPMethod.POST;
66+
}
67+
68+
/**
69+
* @return URI to the endpoint including path parameters
70+
*/
71+
@Override
72+
public String getPath() {
73+
return String.format("/recomms/next/item-segments/%s", this.recommId);
74+
}
75+
76+
/**
77+
* Get query parameters
78+
* @return Values of query parameters (name of parameter: value of the parameter)
79+
*/
80+
@Override
81+
public Map<String, Object> getQueryParameters() {
82+
HashMap<String, Object> params = new HashMap<String, Object>();
83+
return params;
84+
}
85+
86+
/**
87+
* Get body parameters
88+
* @return Values of body parameters (name of parameter: value of the parameter)
89+
*/
90+
@Override
91+
public Map<String, Object> getBodyParameters() {
92+
HashMap<String, Object> params = new HashMap<String, Object>();
93+
params.put("count", this.count);
94+
return params;
95+
}
96+
97+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.recombee.api_client;
2+
/*
3+
This file is auto-generated, do not edit
4+
*/
5+
6+
7+
import com.recombee.api_client.api_requests.*;
8+
import com.recombee.api_client.bindings.*;
9+
import com.recombee.api_client.exceptions.ApiException;
10+
import com.recombee.api_client.exceptions.ResponseException;
11+
12+
import java.util.HashMap;
13+
import java.util.Date;
14+
15+
import org.junit.Test;
16+
import static org.junit.Assert.assertEquals;
17+
import static org.junit.Assert.assertArrayEquals;
18+
import static org.junit.Assert.fail;
19+
20+
public class RecommendNextItemSegmentsBatchTest extends RecombeeTestCase {
21+
22+
@Test
23+
public void testRecommendNextItemSegments() throws ApiException {
24+
Object resp2;
25+
try {
26+
this.client.send(new RecommendNextItemSegments("invalid_recomm_id",5));
27+
fail("No exception thrown");
28+
} catch (ResponseException ex) {
29+
assertEquals(400,ex.getStatusCode());
30+
}
31+
32+
resp2 = this.client.send(new RecommendItemsToUser("entity_id",3));
33+
34+
Request[] requests = new Request[] {
35+
new RecommendNextItemSegments(((RecommendationResponse)resp2).getRecommId(),5)
36+
};
37+
38+
BatchResponse[] responses = this.client.send(new Batch(requests));
39+
assertEquals(400,responses[0].getStatusCode());
40+
}
41+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.recombee.api_client;
2+
/*
3+
This file is auto-generated, do not edit
4+
*/
5+
6+
7+
import com.recombee.api_client.api_requests.*;
8+
import com.recombee.api_client.bindings.*;
9+
import com.recombee.api_client.exceptions.ApiException;
10+
import com.recombee.api_client.exceptions.ResponseException;
11+
12+
import java.util.HashMap;
13+
import java.util.Date;
14+
15+
import org.junit.Test;
16+
import static org.junit.Assert.assertEquals;
17+
import static org.junit.Assert.assertArrayEquals;
18+
import static org.junit.Assert.fail;
19+
20+
public class RecommendNextItemSegmentsTest extends RecombeeTestCase {
21+
22+
@Test
23+
public void testRecommendNextItemSegments() throws ApiException {
24+
RecommendationResponse resp;
25+
Object resp2;
26+
// it 'rejects request with invalid recommId'
27+
try {
28+
this.client.send(new RecommendNextItemSegments("invalid_recomm_id",5));
29+
fail("No exception thrown");
30+
} catch (ResponseException ex) {
31+
assertEquals(400,ex.getStatusCode());
32+
}
33+
// it 'rejects request to recommId which does not return item-segments'
34+
resp2 = this.client.send(new RecommendItemsToUser("entity_id",3));
35+
try {
36+
this.client.send(new RecommendNextItemSegments(((RecommendationResponse)resp2).getRecommId(),5));
37+
fail("No exception thrown");
38+
} catch (ResponseException ex) {
39+
assertEquals(400,ex.getStatusCode());
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)