Skip to content

Commit 17e641d

Browse files
committed
Use new recommendation endpoints
1 parent fc18e99 commit 17e641d

8 files changed

Lines changed: 21 additions & 23 deletions

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ or
1717
```
1818
{
1919
"require": {
20-
"recombee/php-api-client": "^1.6.1"
20+
"recombee/php-api-client": "^2.0.0"
2121
}
2222
}
2323
```
@@ -30,7 +30,7 @@ use Recombee\RecommApi\Client;
3030
use Recombee\RecommApi\Requests as Reqs;
3131
use Recombee\RecommApi\Exceptions as Ex;
3232

33-
$client = new Client('client-test', 'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L');
33+
$client = new Client('--my-database-id--', '--my-secret-token--');
3434

3535
const NUM = 100;
3636
const PROBABILITY_PURCHASED = 0.1;
@@ -55,9 +55,9 @@ try
5555
$res = $client->send(new Reqs\Batch($purchase_requests)); //Use Batch for faster processing of larger data
5656

5757
// Get 5 recommendations for user 'user-25'
58-
$recommended = $client->send(new Reqs\UserBasedRecommendation('user-25', 5));
58+
$recommended = $client->send(new Reqs\RecommendItemsToUser('user-25', 5));
5959

60-
echo 'Recommended items: ' . implode(',',$recommended) . "\n";
60+
echo 'Recommended items: ' . json_encode($recommended, JSON_PRETTY_PRINT) . "\n";
6161
}
6262
catch(Ex\ApiException $e)
6363
{
@@ -74,7 +74,7 @@ use Recombee\RecommApi\Exceptions as Ex;
7474
const NUM = 100;
7575
const PROBABILITY_PURCHASED = 0.1;
7676

77-
$client = new Client('client-test', 'jGGQ6ZKa8rQ1zTAyxTc0EMn55YPF7FJLUtaMLhbsGxmvwxgTwXYqmUk5xVZFw98L');
77+
$client = new Client('--my-database-id--', '--my-secret-token--');
7878
$client->send(new Reqs\ResetDatabase()); //Clear everything from the database
7979

8080
/*
@@ -130,21 +130,21 @@ for($i=0; $i<NUM; $i++)
130130
$client->send(new Reqs\Batch($requests));
131131

132132
// Get 5 items related to item computer-6. Personalize them for user-42, who is currently viewing that item.
133-
$recommended = $client->send(new Reqs\ItemBasedRecommendation('computer-6', 5, ['targetUserId' => 'user-42']));
134-
echo 'Recommended items: ' . implode(',',$recommended) . "\n";
133+
$recommended = $client->send(new Reqs\RecommendItemsToItem('computer-6', 'user-42', 5));
134+
echo 'Recommended items: ' . json_encode($recommended, JSON_PRETTY_PRINT) . "\n";
135135

136136
// Recommend only computers that have at least 3 cores
137137
$recommended = $client->send(
138-
new Reqs\ItemBasedRecommendation('computer-6', 5, ['targetUserId' => 'user-42', 'filter' => "'num-cores'>=3"])
138+
new Reqs\RecommendItemsToItem('computer-6', 'user-42', 5, ['filter' => "'num-cores'>=3"])
139139
);
140-
echo 'Recommended items with at least 3 processor cores: ' . implode(',',$recommended) . "\n";
140+
echo 'Recommended items with at least 3 processor cores: ' . json_encode($recommended, JSON_PRETTY_PRINT) . "\n";
141141

142142
// Recommend only items that are more expensive then currently viewed item computer-6 (up-sell)
143143
$recommended = $client->send(
144-
new Reqs\ItemBasedRecommendation('computer-6', 5,
145-
['targetUserId' => 'user-42', 'filter' => "'price' > context_item[\"price\"]"])
144+
new Reqs\RecommendItemsToItem('computer-6', 'user-42', 5,
145+
['filter' => "'price' > context_item[\"price\"]"])
146146
);
147-
echo 'Recommended up-sell items: ' . implode(',',$recommended) . "\n"
147+
echo 'Recommended up-sell items: ' . json_encode($recommended, JSON_PRETTY_PRINT) . "\n"
148148
```
149149

150150
### Exception handling
@@ -162,8 +162,8 @@ use Recombee\RecommApi\Exceptions as Ex;
162162
try
163163
{
164164
$recommended = $client->send(
165-
new Reqs\ItemBasedRecommendation('computer-6', 5,
166-
['targetUserId' => 'user-42', 'filter' => "'price' > context_item[\"price\"]"])
165+
new Reqs\RecommendItemsToItem('computer-6', 'user-42', 5,
166+
['filter' => "'price' > context_item[\"price\"]"])
167167
);
168168
}
169169
catch(Ex\ApiTimeoutException $e)

src/RecommApi/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected function getOptionalHttpHeaders() {
112112
}
113113

114114
protected function getHttpHeaders() {
115-
return array_merge(array('User-Agent' => 'recombee-php-api-client/1.6.1'), $this->getOptionalHttpHeaders());
115+
return array_merge(array('User-Agent' => 'recombee-php-api-client/2.0.0'), $this->getOptionalHttpHeaders());
116116
}
117117

118118
protected function getOptionalRequestOptions() {

src/RecommApi/Requests/ItemBasedRecommendation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/**
1313
* Recommends set of items that are somehow related to one given item, *X*. Typical scenario for using item-based recommendation is when user *A* is viewing *X*. Then you may display items to the user that he might be also interested in. Item-recommendation request gives you Top-N such items, optionally taking the target user *A* into account.
1414
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
15+
* @deprecated 2.0.0 Use RecommendItemsToItem request instead.
1516
*/
1617
class ItemBasedRecommendation extends Request {
1718

src/RecommApi/Requests/RecommendItemsToItem.php

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

1212
/**
13-
* This feature is currently in beta.
1413
* Recommends set of items that are somehow related to one given item, *X*. Typical scenario is when user *A* is viewing *X*. Then you may display items to the user that he might be also interested in. Recommend items to item request gives you Top-N such items, optionally taking the target user *A* into account.
1514
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
1615
*/
@@ -31,8 +30,8 @@ class RecommendItemsToItem extends Request {
3130
* If you insist on not specifying the user, pass `null`
3231
* (`None`, `nil`, `NULL` etc. depending on language) to *targetUserId*.
3332
* Do not create some special dummy user for getting recommendations,
34-
* as it could cause mislead the recommendation models,
35-
* leading to wrong recommendations.
33+
* as it could mislead the recommendation models,
34+
* and result in wrong recommendations.
3635
* For anonymous/unregistered users it is possible to use for example their session ID.
3736
*/
3837
protected $target_user_id;
@@ -156,8 +155,8 @@ class RecommendItemsToItem extends Request {
156155
* If you insist on not specifying the user, pass `null`
157156
* (`None`, `nil`, `NULL` etc. depending on language) to *targetUserId*.
158157
* Do not create some special dummy user for getting recommendations,
159-
* as it could cause mislead the recommendation models,
160-
* leading to wrong recommendations.
158+
* as it could mislead the recommendation models,
159+
* and result in wrong recommendations.
161160
* For anonymous/unregistered users it is possible to use for example their session ID.
162161
* @param int $count Number of items to be recommended (N for the top-N recommendation).
163162
* @param array $optional Optional parameters given as an array containing pairs name of the parameter => value

src/RecommApi/Requests/RecommendItemsToUser.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
1111

1212
/**
13-
* This feature is currently in beta.
1413
* Based on user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for a given user.
1514
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
1615
*/

src/RecommApi/Requests/RecommendUsersToItem.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
1111

1212
/**
13-
* This feature is currently in beta.
1413
* Recommend users that are likely to be interested in a given item.
1514
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
1615
*/

src/RecommApi/Requests/RecommendUsersToUser.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
1111

1212
/**
13-
* This feature is currently in beta.
1413
* Get similar users as some given user, based on the user's past interactions (purchases, ratings, etc.) and values of properties.
1514
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
1615
*/

src/RecommApi/Requests/UserBasedRecommendation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/**
1313
* Based on user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for a given user.
1414
* It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters.
15+
* @deprecated 2.0.0 Use RecommendItemsToUser request instead.
1516
*/
1617
class UserBasedRecommendation extends Request {
1718

0 commit comments

Comments
 (0)