Skip to content

Commit b617806

Browse files
committed
Support image and imageList item property types
1 parent 64b8750 commit b617806

10 files changed

+28
-27
lines changed

README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ or
1717
```
1818
{
1919
"require": {
20-
"recombee/php-api-client": "^2.0.1"
20+
"recombee/php-api-client": "^2.1.0"
2121
}
2222
}
2323
```
@@ -79,30 +79,35 @@ $client->send(new Reqs\ResetDatabase()); //Clear everything from the database
7979

8080
/*
8181
We will use computers as items in this example
82-
Computers have three properties
82+
Computers have five properties
8383
- price (floating point number)
8484
- number of processor cores (integer number)
8585
- description (string)
86+
- date from which it is in stock (timestamp)
87+
- image (url of computer's photo)
8688
*/
8789

8890
// Add properties of items
8991
$client->send(new Reqs\AddItemProperty('price', 'double'));
9092
$client->send(new Reqs\AddItemProperty('num-cores', 'int'));
9193
$client->send(new Reqs\AddItemProperty('description', 'string'));
9294
$client->send(new Reqs\AddItemProperty('in_stock_from', 'timestamp'));
95+
$client->send(new Reqs\AddItemProperty('image', 'image'));
9396

9497
# Prepare requests for setting a catalog of computers
9598
$requests = array();
9699
for($i=0; $i<NUM; $i++)
97100
{
101+
$itemId = "computer-{$i}";
98102
$r = new Reqs\SetItemValues(
99-
"computer-{$i}", //itemId
103+
$itemId,
100104
//values:
101105
[
102106
'price' => rand(15000, 25000),
103107
'num-cores' => rand(1, 8),
104108
'description' => 'Great computer',
105-
'in_stock_from' => new DateTime('NOW')
109+
'in_stock_from' => new DateTime('NOW'),
110+
'image' => "http://examplesite.com/products/{$itemId}.jpg"
106111
],
107112
//optional parameters:
108113
['cascadeCreate' => true] // Use cascadeCreate for creating item

src/RecommApi/Client.php

+1-1
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/2.0.1'), $this->getOptionalHttpHeaders());
115+
return array_merge(array('User-Agent' => 'recombee-php-api-client/2.1.0'), $this->getOptionalHttpHeaders());
116116
}
117117

118118
protected function getOptionalRequestOptions() {

src/RecommApi/Requests/AddItemProperty.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ class AddItemProperty extends Request {
1919
*/
2020
protected $property_name;
2121
/**
22-
* @var string $type Value type of the item property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`
22+
* @var string $type Value type of the item property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`, `image` or `imageList`.
2323
*/
2424
protected $type;
2525

2626
/**
2727
* Construct the request
2828
* @param string $property_name Name of the item property to be created. Currently, the following names are reserved:`id`, `itemid`, case insensitively. Also, the length of the property name must not exceed 63 characters.
29-
* @param string $type Value type of the item property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`
29+
* @param string $type Value type of the item property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`, `image` or `imageList`.
3030
*/
3131
public function __construct($property_name, $type) {
3232
$this->property_name = $property_name;

src/RecommApi/Requests/DeleteViewPortion.php

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
1111

1212
/**
13-
* The view portions feature is currently experimental.
1413
* Deletes an existing view portion specified by (`userId`, `itemId`, `sessionId`) from the database.
1514
*/
1615
class DeleteViewPortion extends Request {

src/RecommApi/Requests/ItemBasedRecommendation.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ class ItemBasedRecommendation extends Request {
108108
*/
109109
protected $min_relevance;
110110
/**
111-
* @var float $rotation_rate **Expert option** If the *targetUserId* is provided: If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items.
111+
* @var float $rotation_rate **Expert option** If the *targetUserId* is provided: If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. Default: `0.01`.
112112
*/
113113
protected $rotation_rate;
114114
/**
115-
* @var float $rotation_time **Expert option** If the *targetUserId* is provided: Taking *rotationRate* into account, specifies how long time it takes to an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized.
115+
* @var float $rotation_time **Expert option** If the *targetUserId* is provided: Taking *rotationRate* into account, specifies how long time it takes to an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized. Default: `7200.0`.
116116
*/
117117
protected $rotation_time;
118118
/**
@@ -204,10 +204,10 @@ class ItemBasedRecommendation extends Request {
204204
* - Description: **Expert option** If the *targetUserId* is provided: Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested qualit, and may return less than *count* items when there is not enough data to fulfill it.
205205
* - *rotationRate*
206206
* - Type: float
207-
* - Description: **Expert option** If the *targetUserId* is provided: If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items.
207+
* - Description: **Expert option** If the *targetUserId* is provided: If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. Default: `0.01`.
208208
* - *rotationTime*
209209
* - Type: float
210-
* - Description: **Expert option** If the *targetUserId* is provided: Taking *rotationRate* into account, specifies how long time it takes to an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized.
210+
* - Description: **Expert option** If the *targetUserId* is provided: Taking *rotationRate* into account, specifies how long time it takes to an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized. Default: `7200.0`.
211211
* - *expertSettings*
212212
* - Type:
213213
* - Description: Dictionary of custom options.

src/RecommApi/Requests/ListItemViewPortions.php

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
1111

1212
/**
13-
* The view portions feature is currently experimental.
1413
* List all the view portions of an item ever submitted by different users.
1514
*/
1615
class ListItemViewPortions extends Request {

src/RecommApi/Requests/ListUserViewPortions.php

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
1111

1212
/**
13-
* The view portions feature is currently experimental.
1413
* List all the view portions ever submitted by a given user.
1514
*/
1615
class ListUserViewPortions extends Request {

src/RecommApi/Requests/RecommendItemsToUser.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ class RecommendItemsToUser extends Request {
106106
*/
107107
protected $min_relevance;
108108
/**
109-
* @var float $rotation_rate **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items.
109+
* @var float $rotation_rate **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. Default: `0.1`.
110110
*/
111111
protected $rotation_rate;
112112
/**
113-
* @var float $rotation_time **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized.
113+
* @var float $rotation_time **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized. Default: `7200.0`.
114114
*/
115115
protected $rotation_time;
116116
/**
@@ -204,10 +204,10 @@ class RecommendItemsToUser extends Request {
204204
* - Description: **Expert option** Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested relevancy, and may return less than *count* items when there is not enough data to fulfill it.
205205
* - *rotationRate*
206206
* - Type: float
207-
* - Description: **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items.
207+
* - Description: **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. Default: `0.1`.
208208
* - *rotationTime*
209209
* - Type: float
210-
* - Description: **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized.
210+
* - Description: **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized. Default: `7200.0`.
211211
* - *expertSettings*
212212
* - Type:
213213
* - Description: Dictionary of custom options.

src/RecommApi/Requests/SetViewPortion.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
1111

1212
/**
13-
* The view portions feature is currently experimental.
1413
* Sets viewed portion of an item (for example a video or article) by a user (at a session).
1514
* If you send new request with the same (`userId`, `itemId`, `sessionId`), the portion gets updated.
1615
*/
@@ -25,11 +24,11 @@ class SetViewPortion extends Request {
2524
*/
2625
protected $item_id;
2726
/**
28-
* @var float $portion Viewed portion of the item (number between 0.0 (viewed nothing) and 1.0 (viewed full item) ).
27+
* @var float $portion Viewed portion of the item (number between 0.0 (viewed nothing) and 1.0 (viewed full item) ). It should be the really viewed part of the item, no matter seeking, so for example if the user seeked immediately to half of the item and then viewed 10% of the item, the `portion` should still be `0.1`.
2928
*/
3029
protected $portion;
3130
/**
32-
* @var string $session_id Id of session in which the user viewed the item
31+
* @var string $session_id ID of session in which the user viewed the item. Default is `null` (`None`, `nil`, `NULL` etc. depending on language).
3332
*/
3433
protected $session_id;
3534
/**
@@ -49,12 +48,12 @@ class SetViewPortion extends Request {
4948
* Construct the request
5049
* @param string $user_id User who viewed a portion of the item
5150
* @param string $item_id Viewed item
52-
* @param float $portion Viewed portion of the item (number between 0.0 (viewed nothing) and 1.0 (viewed full item) ).
51+
* @param float $portion Viewed portion of the item (number between 0.0 (viewed nothing) and 1.0 (viewed full item) ). It should be the really viewed part of the item, no matter seeking, so for example if the user seeked immediately to half of the item and then viewed 10% of the item, the `portion` should still be `0.1`.
5352
* @param array $optional Optional parameters given as an array containing pairs name of the parameter => value
5453
* - Allowed parameters:
5554
* - *sessionId*
5655
* - Type: string
57-
* - Description: Id of session in which the user viewed the item
56+
* - Description: ID of session in which the user viewed the item. Default is `null` (`None`, `nil`, `NULL` etc. depending on language).
5857
* - *timestamp*
5958
* - Type: string|float
6059
* - Description: UTC timestamp of the rating as ISO8601-1 pattern or UTC epoch time. The default value is the current time.

0 commit comments

Comments
 (0)