-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support endpoints for handling search synonyms. Support also guzzle 6…
… as HTTP client.
- Loading branch information
1 parent
a9fcf9c
commit 0c2f2b0
Showing
15 changed files
with
504 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/* | ||
This file is auto-generated, do not edit | ||
*/ | ||
|
||
/** | ||
* AddSearchSynonym request | ||
*/ | ||
namespace Recombee\RecommApi\Requests; | ||
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException; | ||
|
||
/** | ||
* Adds a new synonym for the [Search items](https://docs.recombee.com/api.html#search-items). | ||
* When the `term` is used in the search query, the `synonym` is also used for the full-text search. | ||
* Unless `oneWay=true`, it works also in the opposite way (`synonym` -> `term`). | ||
* An example of a synonym can be `science fiction` for the term `sci-fi`. | ||
*/ | ||
class AddSearchSynonym extends Request { | ||
|
||
/** | ||
* @var string $term A word to which the `synonym` is specified. | ||
*/ | ||
protected $term; | ||
/** | ||
* @var string $synonym A word that should be considered equal to the `term` by the full-text search engine. | ||
*/ | ||
protected $synonym; | ||
/** | ||
* @var bool $one_way If set to `true`, only `term` -> `synonym` is considered. If set to `false`, also `synonym` -> `term` works. | ||
* Default: `false`. | ||
*/ | ||
protected $one_way; | ||
/** | ||
* @var array Array containing values of optional parameters | ||
*/ | ||
protected $optional; | ||
|
||
/** | ||
* Construct the request | ||
* @param string $term A word to which the `synonym` is specified. | ||
* @param string $synonym A word that should be considered equal to the `term` by the full-text search engine. | ||
* @param array $optional Optional parameters given as an array containing pairs name of the parameter => value | ||
* - Allowed parameters: | ||
* - *oneWay* | ||
* - Type: bool | ||
* - Description: If set to `true`, only `term` -> `synonym` is considered. If set to `false`, also `synonym` -> `term` works. | ||
* Default: `false`. | ||
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional | ||
*/ | ||
public function __construct($term, $synonym, $optional = array()) { | ||
$this->term = $term; | ||
$this->synonym = $synonym; | ||
$this->one_way = isset($optional['oneWay']) ? $optional['oneWay'] : null; | ||
$this->optional = $optional; | ||
|
||
$existing_optional = array('oneWay'); | ||
foreach ($this->optional as $key => $value) { | ||
if (!in_array($key, $existing_optional)) | ||
throw new UnknownOptionalParameterException($key); | ||
} | ||
$this->timeout = 10000; | ||
$this->ensure_https = false; | ||
} | ||
|
||
/** | ||
* Get used HTTP method | ||
* @return static Used HTTP method | ||
*/ | ||
public function getMethod() { | ||
return Request::HTTP_POST; | ||
} | ||
|
||
/** | ||
* Get URI to the endpoint | ||
* @return string URI to the endpoint | ||
*/ | ||
public function getPath() { | ||
return "/{databaseId}/synonyms/items/"; | ||
} | ||
|
||
/** | ||
* Get query parameters | ||
* @return array Values of query parameters (name of parameter => value of the parameter) | ||
*/ | ||
public function getQueryParameters() { | ||
$params = array(); | ||
return $params; | ||
} | ||
|
||
/** | ||
* Get body parameters | ||
* @return array Values of body parameters (name of parameter => value of the parameter) | ||
*/ | ||
public function getBodyParameters() { | ||
$p = array(); | ||
$p['term'] = $this->term; | ||
$p['synonym'] = $this->synonym; | ||
if (isset($this->optional['oneWay'])) | ||
$p['oneWay'] = $this-> optional['oneWay']; | ||
return $p; | ||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/* | ||
This file is auto-generated, do not edit | ||
*/ | ||
|
||
/** | ||
* DeleteAllSearchSynonyms request | ||
*/ | ||
namespace Recombee\RecommApi\Requests; | ||
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException; | ||
|
||
/** | ||
* Deletes all synonyms defined in the database. | ||
*/ | ||
class DeleteAllSearchSynonyms extends Request { | ||
|
||
|
||
/** | ||
* Construct the request | ||
*/ | ||
public function __construct() { | ||
$this->timeout = 10000; | ||
$this->ensure_https = false; | ||
} | ||
|
||
/** | ||
* Get used HTTP method | ||
* @return static Used HTTP method | ||
*/ | ||
public function getMethod() { | ||
return Request::HTTP_DELETE; | ||
} | ||
|
||
/** | ||
* Get URI to the endpoint | ||
* @return string URI to the endpoint | ||
*/ | ||
public function getPath() { | ||
return "/{databaseId}/synonyms/items/"; | ||
} | ||
|
||
/** | ||
* Get query parameters | ||
* @return array Values of query parameters (name of parameter => value of the parameter) | ||
*/ | ||
public function getQueryParameters() { | ||
$params = array(); | ||
return $params; | ||
} | ||
|
||
/** | ||
* Get body parameters | ||
* @return array Values of body parameters (name of parameter => value of the parameter) | ||
*/ | ||
public function getBodyParameters() { | ||
$p = array(); | ||
return $p; | ||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/* | ||
This file is auto-generated, do not edit | ||
*/ | ||
|
||
/** | ||
* DeleteSearchSynonym request | ||
*/ | ||
namespace Recombee\RecommApi\Requests; | ||
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException; | ||
|
||
/** | ||
* Deletes synonym of given `id` and this synonym is no longer taken into account in the [Search items](https://docs.recombee.com/api.html#search-items). | ||
*/ | ||
class DeleteSearchSynonym extends Request { | ||
|
||
/** | ||
* @var string $id ID of the synonym that should be deleted. | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* Construct the request | ||
* @param string $id ID of the synonym that should be deleted. | ||
*/ | ||
public function __construct($id) { | ||
$this->id = $id; | ||
$this->timeout = 10000; | ||
$this->ensure_https = false; | ||
} | ||
|
||
/** | ||
* Get used HTTP method | ||
* @return static Used HTTP method | ||
*/ | ||
public function getMethod() { | ||
return Request::HTTP_DELETE; | ||
} | ||
|
||
/** | ||
* Get URI to the endpoint | ||
* @return string URI to the endpoint | ||
*/ | ||
public function getPath() { | ||
return "/{databaseId}/synonyms/items/{$this->id}"; | ||
} | ||
|
||
/** | ||
* Get query parameters | ||
* @return array Values of query parameters (name of parameter => value of the parameter) | ||
*/ | ||
public function getQueryParameters() { | ||
$params = array(); | ||
return $params; | ||
} | ||
|
||
/** | ||
* Get body parameters | ||
* @return array Values of body parameters (name of parameter => value of the parameter) | ||
*/ | ||
public function getBodyParameters() { | ||
$p = array(); | ||
return $p; | ||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
/* | ||
This file is auto-generated, do not edit | ||
*/ | ||
|
||
/** | ||
* ListSearchSynonyms request | ||
*/ | ||
namespace Recombee\RecommApi\Requests; | ||
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException; | ||
|
||
/** | ||
* Gives the list of synonyms defined in the database. | ||
*/ | ||
class ListSearchSynonyms extends Request { | ||
|
||
/** | ||
* @var int $count The number of synonyms to be listed. | ||
*/ | ||
protected $count; | ||
/** | ||
* @var int $offset Specifies the number of synonyms to skip (ordered by `term`). | ||
*/ | ||
protected $offset; | ||
/** | ||
* @var array Array containing values of optional parameters | ||
*/ | ||
protected $optional; | ||
|
||
/** | ||
* Construct the request | ||
* @param array $optional Optional parameters given as an array containing pairs name of the parameter => value | ||
* - Allowed parameters: | ||
* - *count* | ||
* - Type: int | ||
* - Description: The number of synonyms to be listed. | ||
* - *offset* | ||
* - Type: int | ||
* - Description: Specifies the number of synonyms to skip (ordered by `term`). | ||
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional | ||
*/ | ||
public function __construct($optional = array()) { | ||
$this->count = isset($optional['count']) ? $optional['count'] : null; | ||
$this->offset = isset($optional['offset']) ? $optional['offset'] : null; | ||
$this->optional = $optional; | ||
|
||
$existing_optional = array('count','offset'); | ||
foreach ($this->optional as $key => $value) { | ||
if (!in_array($key, $existing_optional)) | ||
throw new UnknownOptionalParameterException($key); | ||
} | ||
$this->timeout = 100000; | ||
$this->ensure_https = false; | ||
} | ||
|
||
/** | ||
* Get used HTTP method | ||
* @return static Used HTTP method | ||
*/ | ||
public function getMethod() { | ||
return Request::HTTP_GET; | ||
} | ||
|
||
/** | ||
* Get URI to the endpoint | ||
* @return string URI to the endpoint | ||
*/ | ||
public function getPath() { | ||
return "/{databaseId}/synonyms/items/"; | ||
} | ||
|
||
/** | ||
* Get query parameters | ||
* @return array Values of query parameters (name of parameter => value of the parameter) | ||
*/ | ||
public function getQueryParameters() { | ||
$params = array(); | ||
if (isset($this->optional['count'])) | ||
$params['count'] = $this->optional['count']; | ||
if (isset($this->optional['offset'])) | ||
$params['offset'] = $this->optional['offset']; | ||
return $params; | ||
} | ||
|
||
/** | ||
* Get body parameters | ||
* @return array Values of body parameters (name of parameter => value of the parameter) | ||
*/ | ||
public function getBodyParameters() { | ||
$p = array(); | ||
return $p; | ||
} | ||
|
||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
namespace Recombee\RecommApi\Tests; | ||
use Recombee\RecommApi\Requests\AddSearchSynonym; | ||
|
||
class AddSearchSynonymTest extends AddSearchSynonymTestCase { | ||
|
||
protected function createRequest($term, $synonym, $optional=array()) { | ||
return new AddSearchSynonym($term, $synonym, $optional); | ||
} | ||
} | ||
?> |
Oops, something went wrong.