Skip to content

Commit

Permalink
Merge pull request #69 from vyg/main
Browse files Browse the repository at this point in the history
fix: add new search client that uses the correct key
  • Loading branch information
wilr authored May 23, 2024
2 parents f5cbcbb + 6b46069 commit bd56514
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Service/AlgoliaQuerier.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function array_key_first(array $arr)

try {
$selectedIndex = $service->environmentizeIndex($selectedIndex);
$index = $service->getClient()->initIndex($selectedIndex);
$index = $service->getSearchClient()->initIndex($selectedIndex);
$results = $index->search($query, $searchParameters);
} catch (Throwable $e) {
Injector::inst()->get(LoggerInterface::class)->error($e);
Expand Down
22 changes: 22 additions & 0 deletions src/Service/AlgoliaService.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ public function getClient()
return $this->client;
}

/**
* @return \Algolia\AlgoliaSearch\SearchClient
*/
public function getSearchClient()
{
if (!$this->client) {
if (!$this->searchApiKey) {
throw new Exception('No searchApiKey configured for ' . self::class);
}

if (!$this->applicationId) {
throw new Exception('No applicationId configured for ' . self::class);
}

$this->client = SearchClient::create(
$this->applicationId,
$this->searchApiKey
);
}

return $this->client;
}

public function getIndexes($excludeReplicas = true)
{
Expand Down

0 comments on commit bd56514

Please sign in to comment.