Skip to content

Commit f0c5e4f

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

6 files changed

Lines changed: 153 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ or
1717
```
1818
{
1919
"require": {
20-
"recombee/php-api-client": "^6.1.0"
20+
"recombee/php-api-client": "^6.2.0"
2121
}
2222
}
2323
```

src/RecommApi/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function getBaseUri() {
9292
}
9393

9494
protected function getUserAgent() {
95-
$user_agent = 'recombee-php-api-client/6.1.0';
95+
$user_agent = 'recombee-php-api-client/6.2.0';
9696
if (isset($this->options['serviceName']))
9797
$user_agent .= ' '.($this->options['serviceName']);
9898
return $user_agent;

src/RecommApi/Requests/CompositeRecommendation.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
1111

1212
/**
13-
* 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.
13+
* 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.
1414
* 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>*.
1515
* See detailed **examples and configuration guidance** in the [Composite Scenarios documentation](https://docs.recombee.com/scenarios#composite-recommendations).
1616
* **Structure**
@@ -60,6 +60,10 @@ class CompositeRecommendation extends Request {
6060
* @var string $segment_id ID of the segment from `contextSegmentationId` for which the recommendations are to be generated.
6161
*/
6262
protected $segment_id;
63+
/**
64+
* @var string $search_query Search query provided by the user. It is used for the full-text search. Only applicable if the *scenario* corresponds to a search scenario.
65+
*/
66+
protected $search_query;
6367
/**
6468
* @var bool $cascade_create 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.
6569
*/
@@ -104,6 +108,9 @@ class CompositeRecommendation extends Request {
104108
* - *segmentId*
105109
* - Type: string
106110
* - Description: ID of the segment from `contextSegmentationId` for which the recommendations are to be generated.
111+
* - *searchQuery*
112+
* - Type: string
113+
* - Description: Search query provided by the user. It is used for the full-text search. Only applicable if the *scenario* corresponds to a search scenario.
107114
* - *cascadeCreate*
108115
* - Type: bool
109116
* - Description: 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.
@@ -125,13 +132,14 @@ public function __construct($scenario, $count, $optional = array()) {
125132
$this->user_id = isset($optional['userId']) ? $optional['userId'] : null;
126133
$this->logic = isset($optional['logic']) ? $optional['logic'] : null;
127134
$this->segment_id = isset($optional['segmentId']) ? $optional['segmentId'] : null;
135+
$this->search_query = isset($optional['searchQuery']) ? $optional['searchQuery'] : null;
128136
$this->cascade_create = isset($optional['cascadeCreate']) ? $optional['cascadeCreate'] : null;
129137
$this->source_settings = isset($optional['sourceSettings']) ? $optional['sourceSettings'] : null;
130138
$this->result_settings = isset($optional['resultSettings']) ? $optional['resultSettings'] : null;
131139
$this->expert_settings = isset($optional['expertSettings']) ? $optional['expertSettings'] : null;
132140
$this->optional = $optional;
133141

134-
$existing_optional = array('itemId','userId','logic','segmentId','cascadeCreate','sourceSettings','resultSettings','expertSettings');
142+
$existing_optional = array('itemId','userId','logic','segmentId','searchQuery','cascadeCreate','sourceSettings','resultSettings','expertSettings');
135143
foreach ($this->optional as $key => $value) {
136144
if (!in_array($key, $existing_optional))
137145
throw new UnknownOptionalParameterException($key);
@@ -181,6 +189,8 @@ public function getBodyParameters() {
181189
$p['logic'] = $this-> optional['logic'];
182190
if (isset($this->optional['segmentId']))
183191
$p['segmentId'] = $this-> optional['segmentId'];
192+
if (isset($this->optional['searchQuery']))
193+
$p['searchQuery'] = $this-> optional['searchQuery'];
184194
if (isset($this->optional['cascadeCreate']))
185195
$p['cascadeCreate'] = $this-> optional['cascadeCreate'];
186196
if (isset($this->optional['sourceSettings']))
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/*
3+
This file is auto-generated, do not edit
4+
*/
5+
6+
/**
7+
* RecommendNextItemSegments request
8+
*/
9+
namespace Recombee\RecommApi\Requests;
10+
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
11+
12+
/**
13+
* 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.
14+
* 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`).
15+
* The base request can be one of:
16+
* - [Recommend Item Segments to Item](https://docs.recombee.com/api#recommend-item-segments-to-item)
17+
* - [Recommend Item Segments to User](https://docs.recombee.com/api#recommend-item-segments-to-user)
18+
* - [Recommend Item Segments to Item Segment](https://docs.recombee.com/api#recommend-item-segments-to-item-segment)
19+
* - [Search Item Segments](https://docs.recombee.com/api#search-item-segments)
20+
* All the other parameters are inherited from the base request.
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+
* *Recommend next Item segments* can be requested up to 30 minutes after the base request or a previous *Recommend next Item segments* call.
24+
* For billing purposes, each call to *Recommend next Item segments* is counted as a separate recommendation request.
25+
*/
26+
class RecommendNextItemSegments extends Request {
27+
28+
/**
29+
* @var string $recomm_id ID of the base recommendation request for which next recommendations should be returned
30+
*/
31+
protected $recomm_id;
32+
/**
33+
* @var int $count Number of item segments to be recommended
34+
*/
35+
protected $count;
36+
37+
/**
38+
* Construct the request
39+
* @param string $recomm_id ID of the base recommendation request for which next recommendations should be returned
40+
* @param int $count Number of item segments to be recommended
41+
*/
42+
public function __construct($recomm_id, $count) {
43+
$this->recomm_id = $recomm_id;
44+
$this->count = $count;
45+
$this->timeout = 3000;
46+
$this->ensure_https = false;
47+
}
48+
49+
/**
50+
* Get used HTTP method
51+
* @return static Used HTTP method
52+
*/
53+
public function getMethod() {
54+
return Request::HTTP_POST;
55+
}
56+
57+
/**
58+
* Get URI to the endpoint
59+
* @return string URI to the endpoint
60+
*/
61+
public function getPath() {
62+
return "/{databaseId}/recomms/next/item-segments/{$this->recomm_id}";
63+
}
64+
65+
/**
66+
* Get query parameters
67+
* @return array Values of query parameters (name of parameter => value of the parameter)
68+
*/
69+
public function getQueryParameters() {
70+
$params = array();
71+
return $params;
72+
}
73+
74+
/**
75+
* Get body parameters
76+
* @return array Values of body parameters (name of parameter => value of the parameter)
77+
*/
78+
public function getBodyParameters() {
79+
$p = array();
80+
$p['count'] = $this->count;
81+
return $p;
82+
}
83+
84+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is auto-generated, do not edit
5+
*/
6+
7+
namespace Recombee\RecommApi\Tests;
8+
9+
use Recombee\RecommApi\Exceptions as Exc;
10+
use Recombee\RecommApi\Requests as Reqs;
11+
12+
abstract class NextItemSegmentsRecommendationTestCase extends RecombeeTestCase {
13+
14+
abstract protected function createRequest($recomm_id,$count);
15+
16+
public function testNextItemSegmentsRecommendation() {
17+
18+
//it rejects request with invalid recommId
19+
$req = new Reqs\RecommendNextItemSegments('invalid_recomm_id',5);
20+
try {
21+
22+
$this->client->send($req);
23+
throw new \Exception('Exception was not thrown');
24+
}
25+
catch(Exc\ResponseException $e)
26+
{
27+
$this->assertEquals(400, $e->status_code);
28+
}
29+
30+
//it rejects request to recommId which does not return item-segments
31+
$req = new Reqs\RecommendItemsToUser('entity_id',3);
32+
$resp = $this->client->send($req);
33+
$req = $this->createRequest($resp['recommId'],5);
34+
try {
35+
36+
$this->client->send($req);
37+
throw new \Exception('Exception was not thrown');
38+
}
39+
catch(Exc\ResponseException $e)
40+
{
41+
$this->assertEquals(400, $e->status_code);
42+
}
43+
44+
}
45+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace Recombee\RecommApi\Tests;
3+
use Recombee\RecommApi\Requests\RecommendNextItemSegments;
4+
5+
class RecommendNextItemSegmentsTest extends NextItemSegmentsRecommendationTestCase {
6+
7+
protected function createRequest($recomm_id, $count) {
8+
return new RecommendNextItemSegments($recomm_id, $count);
9+
}
10+
}

0 commit comments

Comments
 (0)