-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add custom dictionary methods (tests still WIP) * chore: add docblocks * feat: update tests * debug: use API key dealer * Revert "debug: use API key dealer" This reverts commit dcf05df. * feat: refactor tests to rely on objectID checks instead of nbHits * feat: finzalize CTS * chore: address feedback * chore: remove unused method * Add missing part of the url for stopABTest() method (#666) * Handling of param array in the $queries array for multipleQueries method (#663) * Add Algolia CTS (#665) * Indexing and Settings tests for SearchIndexTest.php * Add SearchTest method * Add SynonymsTest method * Add testQueryRules method * Add testBatching method * Add testReplacing and testExists methods + move sample data * Add SearchClientTest.php * Add multiQueries test * Adding AccountTest.php and remove usage of SyncClient * Adding SecuredApiKeysTest * Adding AnalyticsClientTest.php * Adding AnalyticsClientTest.php * Adding InsightsClientTest.php * Adding RecommendationClientTest.php + CS fixer * Adding Mcm tests * Add stopAbTest() test * Remove unnecessary files * Handling of param array in the $queries array for multipleQueries method (#663) * Remove unnecessary files * First required changes * Removing self::assert* notations * fix(cts): delete indexes initialisation * Using wait() on saveObject() rather than multiResponse * Removing all static arrays for indices * Removing unwanted setPersonalizationStrategy call * use secured index name * Required changes after code review * Adding loop to check if indices exist before additing the A/B Tests * Adding security into loops * Set cpts to 10 * Set cpts to 20 * Set cpts to 10 * Set cpts to 10 Co-authored-by: Chloe Liban <[email protected]> * chore(CTS): add retry on tests (#672) * chore(cts): fix api keys test * chore(CTS): fix flakiness * Revert "feat: custom dictionaries (#662)" This reverts commit d4e3112. * chore: address feedback * chore: remove unused method * chore(test): fix helper call * fix: rebase Co-authored-by: Devin Beeuwkes <[email protected]> Co-authored-by: Damien Couchez <[email protected]>
- Loading branch information
1 parent
1c133ca
commit 7f94af6
Showing
3 changed files
with
407 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Algolia\AlgoliaSearch\Response; | ||
|
||
use Algolia\AlgoliaSearch\Config\SearchConfig; | ||
use Algolia\AlgoliaSearch\RequestOptions\RequestOptions; | ||
use Algolia\AlgoliaSearch\SearchClient; | ||
|
||
final class DictionaryResponse extends AbstractResponse | ||
{ | ||
/* @var \Algolia\AlgoliaSearch\SearchClient */ | ||
private $client; | ||
|
||
/* @var \Algolia\AlgoliaSearch\Config\SearchConfig */ | ||
private $config; | ||
|
||
/* @var bool */ | ||
private $done = false; | ||
|
||
/** | ||
* DictionaryResponse constructor. | ||
*/ | ||
public function __construct(array $apiResponse, SearchClient $client, SearchConfig $config) | ||
{ | ||
$this->apiResponse = $apiResponse; | ||
$this->client = $client; | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* Wait for the task from this response to finish. | ||
* | ||
* @param array|RequestOptions $requestOptions | ||
* | ||
* @return $this | ||
*/ | ||
public function wait($requestOptions = array()) | ||
{ | ||
$retryCount = 1; | ||
$time = $this->config->getWaitTaskTimeBeforeRetry(); | ||
|
||
while (!$this->done) { | ||
$res = $this->getTask($this->apiResponse['taskID'], $requestOptions); | ||
|
||
if ('published' === $res['status']) { | ||
$this->done = true; | ||
break; | ||
} | ||
|
||
$retryCount++; | ||
$factor = ceil($retryCount / 10); | ||
usleep($factor * $time); // 0.1 second | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get the task details. | ||
* | ||
* @param int|string $taskId | ||
* @param array|RequestOptions $requestOptions | ||
* | ||
* @return mixed | ||
*/ | ||
private function getTask($taskId, $requestOptions = array()) | ||
{ | ||
if (!$taskId) { | ||
throw new \InvalidArgumentException('taskID cannot be empty'); | ||
} | ||
|
||
return $this->client->custom( | ||
'GET', | ||
\Algolia\AlgoliaSearch\api_path('/1/task/%s', $taskId), | ||
$requestOptions | ||
); | ||
} | ||
} |
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
Oops, something went wrong.