Skip to content

Commit 0410a10

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

6 files changed

Lines changed: 117 additions & 7 deletions

File tree

lib/recombee_api_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class RecombeeClient
1919
include HTTParty
2020

2121
BATCH_MAX_SIZE = 10_000
22-
USER_AGENT = { 'User-Agent' => 'recombee-ruby-api-client/6.1.0' }
22+
USER_AGENT = { 'User-Agent' => 'recombee-ruby-api-client/6.2.0' }
2323

2424
##
2525
# - +account+ -> Name of your account at Recombee

lib/recombee_api_client/api/composite_recommendation.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module RecombeeApiClient
77
require_relative '../errors'
88

99
##
10-
# 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.
10+
# 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.
1111
#
1212
# 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>*.
1313
#
@@ -37,8 +37,8 @@ module RecombeeApiClient
3737
# See [this example](https://docs.recombee.com/api#composite-recommendation-example-setting-parameters-for-individual-stages) for more details.
3838
#
3939
class CompositeRecommendation < ApiRequest
40-
attr_reader :scenario, :count, :item_id, :user_id, :logic, :segment_id, :cascade_create, :source_settings,
41-
:result_settings, :expert_settings
40+
attr_reader :scenario, :count, :item_id, :user_id, :logic, :segment_id, :search_query, :cascade_create,
41+
:source_settings, :result_settings, :expert_settings
4242
attr_accessor :timeout, :ensure_https
4343

4444
##
@@ -66,6 +66,8 @@ class CompositeRecommendation < ApiRequest
6666
#
6767
# - +segmentId+ -> ID of the segment from `contextSegmentationId` for which the recommendations are to be generated.
6868
#
69+
# - +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.
70+
#
6971
# - +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.
7072
#
7173
# - +sourceSettings+ -> Parameters applied for recommending the *Source* stage. The accepted parameters correspond with the recommendation sub-endpoint used to recommend the *Source*.
@@ -83,6 +85,7 @@ def initialize(scenario, count, optional = {})
8385
@user_id = optional['userId']
8486
@logic = optional['logic']
8587
@segment_id = optional['segmentId']
88+
@search_query = optional['searchQuery']
8689
@cascade_create = optional['cascadeCreate']
8790
@source_settings = optional['sourceSettings']
8891
@result_settings = optional['resultSettings']
@@ -91,8 +94,8 @@ def initialize(scenario, count, optional = {})
9194
@timeout = 3000
9295
@ensure_https = false
9396
@optional.each do |par, _|
94-
raise UnknownOptionalParameter.new(par) unless %w[itemId userId logic segmentId cascadeCreate
95-
sourceSettings resultSettings expertSettings].include? par
97+
raise UnknownOptionalParameter.new(par) unless %w[itemId userId logic segmentId searchQuery
98+
cascadeCreate sourceSettings resultSettings expertSettings].include? par
9699
end
97100
end
98101

@@ -110,6 +113,7 @@ def body_parameters
110113
p['userId'] = @optional['userId'] if @optional.include? 'userId'
111114
p['logic'] = @optional['logic'] if @optional.include? 'logic'
112115
p['segmentId'] = @optional['segmentId'] if @optional.include? 'segmentId'
116+
p['searchQuery'] = @optional['searchQuery'] if @optional.include? 'searchQuery'
113117
p['cascadeCreate'] = @optional['cascadeCreate'] if @optional.include? 'cascadeCreate'
114118
p['sourceSettings'] = @optional['sourceSettings'] if @optional.include? 'sourceSettings'
115119
p['resultSettings'] = @optional['resultSettings'] if @optional.include? 'resultSettings'
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#
2+
# This file is auto-generated, do not edit
3+
#
4+
5+
module RecombeeApiClient
6+
require_relative 'request'
7+
require_relative '../errors'
8+
9+
##
10+
# 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.
11+
#
12+
# 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`).
13+
# The base request can be one of:
14+
# - [Recommend Item Segments to Item](https://docs.recombee.com/api#recommend-item-segments-to-item)
15+
# - [Recommend Item Segments to User](https://docs.recombee.com/api#recommend-item-segments-to-user)
16+
# - [Recommend Item Segments to Item Segment](https://docs.recombee.com/api#recommend-item-segments-to-item-segment)
17+
# - [Search Item Segments](https://docs.recombee.com/api#search-item-segments)
18+
#
19+
# All the other parameters are inherited from the base request.
20+
#
21+
# *Recommend next Item segments* can be called many times for a single `recommId` and each call returns different (previously not recommended) segments.
22+
# The number of *Recommend next Item segments* calls performed so far is returned in the `numberNextRecommsCalls` field.
23+
#
24+
# *Recommend next Item segments* can be requested up to 30 minutes after the base request or a previous *Recommend next Item segments* call.
25+
#
26+
# For billing purposes, each call to *Recommend next Item segments* is counted as a separate recommendation request.
27+
#
28+
class RecommendNextItemSegments < ApiRequest
29+
attr_reader :recomm_id, :count
30+
attr_accessor :timeout, :ensure_https
31+
32+
##
33+
# * *Required arguments*
34+
# - +recomm_id+ -> ID of the base recommendation request for which next recommendations should be returned
35+
# - +count+ -> Number of item segments to be recommended
36+
#
37+
#
38+
def initialize(recomm_id, count)
39+
@recomm_id = recomm_id
40+
@count = count
41+
@timeout = 3000
42+
@ensure_https = false
43+
end
44+
45+
# HTTP method
46+
def method
47+
:post
48+
end
49+
50+
# Values of body parameters as a Hash
51+
def body_parameters
52+
p = {}
53+
p['count'] = @count
54+
55+
p
56+
end
57+
58+
# Values of query parameters as a Hash.
59+
# name of parameter => value of the parameter
60+
def query_parameters
61+
{}
62+
end
63+
64+
# Relative path to the endpoint
65+
def path
66+
"/{databaseId}/recomms/next/item-segments/#{@recomm_id}"
67+
end
68+
end
69+
end

lib/recombee_api_client/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module RecombeeApiClient
2-
VERSION = '6.1.0'
2+
VERSION = '6.2.0'
33
end
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#
2+
# This file is auto-generated, do not edit
3+
#
4+
5+
require 'spec_helper'
6+
require_relative 'set_environment'
7+
shared_examples 'next item segments recommendation' do
8+
include_context 'set environment'
9+
10+
it 'rejects request with invalid recommId' do
11+
req = RecommendNextItemSegments.new('invalid_recomm_id', 5)
12+
expect { @client.send(req) }.to(raise_exception do |exception|
13+
expect(exception).to be_a(RecombeeApiClient::ResponseError)
14+
expect(exception.status_code).to eq 400
15+
end)
16+
end
17+
18+
it 'rejects request to recommId which does not return item-segments' do
19+
req = RecommendItemsToUser.new('entity_id', 3)
20+
resp = @client.send(req)
21+
req = described_class.new(resp['recommId'], 5)
22+
expect { @client.send(req) }.to(raise_exception do |exception|
23+
expect(exception).to be_a(RecombeeApiClient::ResponseError)
24+
expect(exception.status_code).to eq 400
25+
end)
26+
end
27+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# This file is auto-generated, do not edit
3+
#
4+
5+
require 'spec_helper'
6+
require_relative 'next_item_segments_recommendation'
7+
8+
describe RecombeeApiClient::RecommendNextItemSegments do
9+
it_behaves_like 'next item segments recommendation'
10+
end

0 commit comments

Comments
 (0)