Skip to content

Commit aa4477d

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

7 files changed

Lines changed: 272 additions & 4 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
This file is auto-generated, do not edit
3+
*/
4+
5+
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using Xunit;
10+
using Recombee.ApiClient.ApiRequests;
11+
using Recombee.ApiClient.Bindings;
12+
13+
namespace Recombee.ApiClient.Tests
14+
{
15+
public class RecommendNextItemSegmentsBatchUnitTest: RecombeeUnitTest
16+
{
17+
18+
[Fact]
19+
public void TestRecommendNextItemSegments()
20+
{
21+
Object resp2;
22+
try
23+
{
24+
client.Send(new RecommendNextItemSegments("invalid_recomm_id", 5));
25+
Assert.True(false,"No exception thrown");
26+
}
27+
catch (ResponseException ex)
28+
{
29+
Assert.Equal(400, (int)ex.StatusCode);
30+
}
31+
32+
resp2 = client.Send(new RecommendItemsToUser("entity_id", 3));
33+
34+
Request[] requests = new Request[] {
35+
new RecommendNextItemSegments(((RecommendationResponse)resp2).RecommId, 5)
36+
};
37+
38+
BatchResponse batchResponse = client.Send(new Batch(requests));
39+
Assert.Equal(400, (int)batchResponse.StatusCodes.ElementAt(0));
40+
}
41+
42+
[Fact]
43+
public async void TestRecommendNextItemSegmentsAsync()
44+
{
45+
Object resp2;
46+
try
47+
{
48+
await client.SendAsync(new RecommendNextItemSegments("invalid_recomm_id", 5));
49+
Assert.True(false,"No exception thrown");
50+
}
51+
catch (ResponseException ex)
52+
{
53+
Assert.Equal(400, (int)ex.StatusCode);
54+
}
55+
56+
resp2 = await client.SendAsync(new RecommendItemsToUser("entity_id", 3));
57+
58+
Request[] requests = new Request[] {
59+
new RecommendNextItemSegments(((RecommendationResponse)resp2).RecommId, 5)
60+
};
61+
62+
BatchResponse batchResponse = await client.SendAsync(new Batch(requests));
63+
Assert.Equal(400, (int)batchResponse.StatusCodes.ElementAt(0));
64+
}
65+
}
66+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
This file is auto-generated, do not edit
3+
*/
4+
5+
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using Xunit;
10+
using Recombee.ApiClient.ApiRequests;
11+
using Recombee.ApiClient.Bindings;
12+
13+
namespace Recombee.ApiClient.Tests
14+
{
15+
public class RecommendNextItemSegmentsUnitTest: RecombeeUnitTest
16+
{
17+
18+
[Fact]
19+
public void TestRecommendNextItemSegments()
20+
{
21+
RecommendNextItemSegments req;
22+
RecommendationResponse resp;
23+
Object resp2;
24+
// it 'rejects request with invalid recommId'
25+
try
26+
{
27+
client.Send(new RecommendNextItemSegments("invalid_recomm_id", 5));
28+
Assert.True(false,"No exception thrown");
29+
}
30+
catch (ResponseException ex)
31+
{
32+
Assert.Equal(400, (int)ex.StatusCode);
33+
}
34+
// it 'rejects request to recommId which does not return item-segments'
35+
resp2 = client.Send(new RecommendItemsToUser("entity_id", 3));
36+
try
37+
{
38+
client.Send(new RecommendNextItemSegments(((RecommendationResponse)resp2).RecommId, 5));
39+
Assert.True(false,"No exception thrown");
40+
}
41+
catch (ResponseException ex)
42+
{
43+
Assert.Equal(400, (int)ex.StatusCode);
44+
}
45+
}
46+
47+
[Fact]
48+
public async void TestRecommendNextItemSegmentsAsync()
49+
{
50+
RecommendNextItemSegments req;
51+
RecommendationResponse resp;
52+
Object resp2;
53+
// it 'rejects request with invalid recommId'
54+
try
55+
{
56+
await client.SendAsync(new RecommendNextItemSegments("invalid_recomm_id", 5));
57+
Assert.True(false,"No exception thrown");
58+
}
59+
catch (ResponseException ex)
60+
{
61+
Assert.Equal(400, (int)ex.StatusCode);
62+
}
63+
// it 'rejects request to recommId which does not return item-segments'
64+
resp2 = await client.SendAsync(new RecommendItemsToUser("entity_id", 3));
65+
try
66+
{
67+
await client.SendAsync(new RecommendNextItemSegments(((RecommendationResponse)resp2).RecommId, 5));
68+
Assert.True(false,"No exception thrown");
69+
}
70+
catch (ResponseException ex)
71+
{
72+
Assert.Equal(400, (int)ex.StatusCode);
73+
}
74+
}
75+
}
76+
}

Src/Recombee.ApiClient/ApiRequests/CompositeRecommendation.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Recombee.ApiClient.ApiRequests
1313
{
1414
/// <summary>Composite Recommendation</summary>
15-
/// <remarks>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.
15+
/// <remarks>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.
1616
/// It is ideal for use cases such as personalized homepage sections (*Articles from <category>*), *Because You Watched <movie>*, or *Artists Related to Your Favorite Artist <artist>*.
1717
/// See detailed **examples and configuration guidance** in the [Composite Scenarios documentation](https://docs.recombee.com/scenarios#composite-recommendations).
1818
/// **Structure**
@@ -80,6 +80,13 @@ public string SegmentId
8080
{
8181
get {return segmentId;}
8282
}
83+
private readonly string searchQuery;
84+
/// <summary>Search query provided by the user. It is used for the full-text search. Only applicable if the *scenario* corresponds to a search scenario.
85+
/// </summary>
86+
public string SearchQuery
87+
{
88+
get {return searchQuery;}
89+
}
8390
private readonly bool? cascadeCreate;
8491
/// <summary>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.
8592
/// </summary>
@@ -127,6 +134,8 @@ public Dictionary<string, object> ExpertSettings
127134
/// </param>
128135
/// <param name="segmentId">ID of the segment from `contextSegmentationId` for which the recommendations are to be generated.
129136
/// </param>
137+
/// <param name="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.
138+
/// </param>
130139
/// <param name="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.
131140
/// </param>
132141
/// <param name="sourceSettings">Parameters applied for recommending the *Source* stage. The accepted parameters correspond with the recommendation sub-endpoint used to recommend the *Source*.
@@ -135,14 +144,15 @@ public Dictionary<string, object> ExpertSettings
135144
/// </param>
136145
/// <param name="expertSettings">Dictionary of custom options.
137146
/// </param>
138-
public CompositeRecommendation (string scenario, long count, string itemId = null, string userId = null, Logic logic = null, string segmentId = null, bool? cascadeCreate = null, CompositeRecommendationStageParameters sourceSettings = null, CompositeRecommendationStageParameters resultSettings = null, Dictionary<string, object> expertSettings = null): base(HttpMethod.Post, 3000)
147+
public CompositeRecommendation (string scenario, long count, string itemId = null, string userId = null, Logic logic = null, string segmentId = null, string searchQuery = null, bool? cascadeCreate = null, CompositeRecommendationStageParameters sourceSettings = null, CompositeRecommendationStageParameters resultSettings = null, Dictionary<string, object> expertSettings = null): base(HttpMethod.Post, 3000)
139148
{
140149
this.scenario = scenario;
141150
this.count = count;
142151
this.itemId = itemId;
143152
this.userId = userId;
144153
this.logic = logic;
145154
this.segmentId = segmentId;
155+
this.searchQuery = searchQuery;
146156
this.cascadeCreate = cascadeCreate;
147157
this.sourceSettings = sourceSettings;
148158
this.resultSettings = resultSettings;
@@ -183,6 +193,8 @@ public override Dictionary<string, object> BodyParameters()
183193
parameters["logic"] = this.Logic;
184194
if (this.SegmentId != null)
185195
parameters["segmentId"] = this.SegmentId;
196+
if (this.SearchQuery != null)
197+
parameters["searchQuery"] = this.SearchQuery;
186198
if (this.CascadeCreate.HasValue)
187199
parameters["cascadeCreate"] = this.CascadeCreate.Value;
188200
if (this.SourceSettings != null)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
This file is auto-generated, do not edit
3+
*/
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Net.Http;
8+
using Recombee.ApiClient.Bindings;
9+
using Recombee.ApiClient.Util;
10+
11+
12+
namespace Recombee.ApiClient.ApiRequests
13+
{
14+
/// <summary>Recommend Next Item segments</summary>
15+
/// <remarks>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.
16+
/// 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`).
17+
/// The base request can be one of:
18+
/// - [Recommend Item Segments to Item](https://docs.recombee.com/api#recommend-item-segments-to-item)
19+
/// - [Recommend Item Segments to User](https://docs.recombee.com/api#recommend-item-segments-to-user)
20+
/// - [Recommend Item Segments to Item Segment](https://docs.recombee.com/api#recommend-item-segments-to-item-segment)
21+
/// - [Search Item Segments](https://docs.recombee.com/api#search-item-segments)
22+
/// All the other parameters are inherited from the base request.
23+
/// *Recommend next Item segments* can be called many times for a single `recommId` and each call returns different (previously not recommended) segments.
24+
/// The number of *Recommend next Item segments* calls performed so far is returned in the `numberNextRecommsCalls` field.
25+
/// *Recommend next Item segments* can be requested up to 30 minutes after the base request or a previous *Recommend next Item segments* call.
26+
/// For billing purposes, each call to *Recommend next Item segments* is counted as a separate recommendation request.
27+
/// </remarks>
28+
public class RecommendNextItemSegments : Request
29+
{
30+
private readonly string recommId;
31+
/// <summary>ID of the base recommendation request for which next recommendations should be returned</summary>
32+
public string RecommId
33+
{
34+
get {return recommId;}
35+
}
36+
private readonly long count;
37+
/// <summary>Number of item segments to be recommended
38+
/// </summary>
39+
public long Count
40+
{
41+
get {return count;}
42+
}
43+
44+
/// <summary>Construct the request</summary>
45+
/// <param name="recommId">ID of the base recommendation request for which next recommendations should be returned</param>
46+
/// <param name="count">Number of item segments to be recommended
47+
/// </param>
48+
public RecommendNextItemSegments (string recommId, long count): base(HttpMethod.Post, 3000)
49+
{
50+
this.recommId = recommId;
51+
this.count = count;
52+
}
53+
54+
/// <returns>URI to the endpoint including path parameters</returns>
55+
public override string Path()
56+
{
57+
return string.Format("/recomms/next/item-segments/{0}", RecommId);
58+
}
59+
60+
/// <summary>Get query parameters</summary>
61+
/// <returns>Dictionary containing values of query parameters (name of parameter: value of the parameter)</returns>
62+
public override Dictionary<string, object> QueryParameters()
63+
{
64+
var parameters = new Dictionary<string, object>()
65+
{
66+
67+
};
68+
return parameters;
69+
}
70+
71+
/// <summary>Get body parameters</summary>
72+
/// <returns>Dictionary containing values of body parameters (name of parameter: value of the parameter)</returns>
73+
public override Dictionary<string, object> BodyParameters()
74+
{
75+
var parameters = new Dictionary<string, object>()
76+
{
77+
{"count", this.Count}
78+
};
79+
return parameters;
80+
}
81+
82+
}
83+
}

Src/Recombee.ApiClient/Recombee.ApiClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</ItemGroup>
1313

1414
<PropertyGroup>
15-
<Version>6.1.0</Version>
15+
<Version>6.2.0</Version>
1616
</PropertyGroup>
1717

1818
<ItemGroup>

Src/Recombee.ApiClient/RecombeeClient.Generated.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,35 @@ public RecommendationResponse Send(RecommendItemSegmentsToItemSegment request)
854854
}
855855

856856

857+
/// <summary>Parse JSON response</summary>
858+
/// <param name="json">JSON string from the API</param>
859+
/// <param name="request">Request sent to the API</param>
860+
/// <returns>Parsed response</returns>
861+
protected RecommendationResponse ParseResponse(string json, RecommendNextItemSegments request)
862+
{
863+
return JsonConvert.DeserializeObject<RecommendationResponse>(json);
864+
}
865+
866+
/// <summary>Asynchronously send the RecommendNextItemSegments request</summary>
867+
/// <param name="request">Request to be sent</param>
868+
/// <returns>Task representing the asynchronous operation</returns>
869+
public async Task<RecommendationResponse> SendAsync(RecommendNextItemSegments request)
870+
{
871+
var json = await SendRequestAsync(request);
872+
return ParseResponse(json, request);
873+
}
874+
875+
/// <summary>Synchronously send the RecommendNextItemSegments request</summary>
876+
/// <param name="request">Request to be sent</param>
877+
/// <returns>Response from the API</returns>
878+
public RecommendationResponse Send(RecommendNextItemSegments request)
879+
{
880+
var task = Task.Run(async () => await SendAsync(request));
881+
var result = task.WaitAndUnwrapException();
882+
return result;
883+
}
884+
885+
857886
/// <summary>Parse JSON response</summary>
858887
/// <param name="json">JSON string from the API</param>
859888
/// <param name="request">Request sent to the API</param>
@@ -1155,6 +1184,8 @@ private object ParseOneBatchResponse(string json, int statusCode, Request reques
11551184

11561185
if (request is RecommendItemSegmentsToItemSegment) return ParseResponse(json, (RecommendItemSegmentsToItemSegment) request);
11571186

1187+
if (request is RecommendNextItemSegments) return ParseResponse(json, (RecommendNextItemSegments) request);
1188+
11581189
if (request is CompositeRecommendation) return ParseResponse(json, (CompositeRecommendation) request);
11591190

11601191
if (request is SearchItems) return ParseResponse(json, (SearchItems) request);

Src/Recombee.ApiClient/RecombeeClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private string getHostUri(string baseUri, Region? region) {
9292
private HttpClient createHttpClient()
9393
{
9494
var httpClient = new HttpClient();
95-
httpClient.DefaultRequestHeaders.Add("User-Agent", "recombee-.net-api-client/6.1.0");
95+
httpClient.DefaultRequestHeaders.Add("User-Agent", "recombee-.net-api-client/6.2.0");
9696
return httpClient;
9797
}
9898

0 commit comments

Comments
 (0)