diff --git a/src/Engine.php b/src/Engine.php index 7d6733cd..b54c6c5c 100644 --- a/src/Engine.php +++ b/src/Engine.php @@ -53,19 +53,19 @@ public function index($searchableEntities): array continue; } - $indexName = $entity->getIndexName(); + $indexUid = $entity->getIndexUid(); - if (!isset($data[$indexName])) { - $data[$indexName] = []; + if (!isset($data[$indexUid])) { + $data[$indexUid] = []; } - $data[$indexName][] = $searchableArray + ['objectID' => $entity->getId()]; + $data[$indexUid][] = $searchableArray + ['objectID' => $entity->getId()]; } $result = []; - foreach ($data as $indexName => $objects) { - $result[$indexName] = $this->client - ->getOrCreateIndex($indexName, ['primaryKey' => 'objectID']) + foreach ($data as $indexUid => $objects) { + $result[$indexUid] = $this->client + ->getOrCreateIndex($indexUid, ['primaryKey' => 'objectID']) ->addDocuments($objects); } @@ -94,19 +94,19 @@ public function remove($searchableEntities): array if (null === $searchableArray || 0 === count($searchableArray)) { continue; } - $indexName = $entity->getIndexName(); + $indexUid = $entity->getIndexName(); - if (!isset($data[$indexName])) { - $data[$indexName] = []; + if (!isset($data[$indexUid])) { + $data[$indexUid] = []; } - $data[$indexName][] = $entity->getId(); + $data[$indexUid][] = $entity->getId(); } $result = []; - foreach ($data as $indexName => $objects) { - $result[$indexName] = $this->client - ->index($indexName) + foreach ($data as $indexUid => $objects) { + $result[$indexUid] = $this->client + ->index($indexUid) ->deleteDocument(reset($objects)); } @@ -117,15 +117,15 @@ public function remove($searchableEntities): array * Clear the records of an index. * This method enables you to delete an index’s contents (records). * - * @param string $indexName + * @param string $indexUid * * @return array * * @throws ApiException */ - public function clear(string $indexName): array + public function clear(string $indexUid): array { - $index = $this->client->getOrCreateIndex($indexName); + $index = $this->client->getOrCreateIndex($indexUid); $return = $index->deleteAllDocuments(); return $index->getUpdateStatus($return['updateId']); @@ -134,44 +134,44 @@ public function clear(string $indexName): array /** * Delete an index and it's content. * - * @param string $indexName + * @param string $indexUid * * @return array|null */ - public function delete(string $indexName): ?array + public function delete(string $indexUid): ?array { - return $this->client->deleteIndex($indexName); + return $this->client->deleteIndex($indexUid); } /** * Method used for querying an index. * * @param string $query - * @param string $indexName + * @param string $indexUid * @param array $searchParams * * @return array */ - public function search(string $query, string $indexName, array $searchParams): array + public function search(string $query, string $indexUid, array $searchParams): array { if ('' === $query) { $query = null; } - return $this->client->index($indexName)->rawSearch($query, $searchParams); + return $this->client->index($indexUid)->rawSearch($query, $searchParams); } /** * Search the index and returns the number of results. * * @param string $query - * @param string $indexName + * @param string $indexUid * @param array $requestOptions * * @return int */ - public function count(string $query, string $indexName, array $requestOptions): int + public function count(string $query, string $indexUid, array $requestOptions): int { - return (int) $this->client->index($indexName)->search($query, $requestOptions)['nbHits']; + return (int) $this->client->index($indexUid)->search($query, $requestOptions)['nbHits']; } } diff --git a/src/SearchableEntity.php b/src/SearchableEntity.php index 4bda1d6c..58688a00 100644 --- a/src/SearchableEntity.php +++ b/src/SearchableEntity.php @@ -17,7 +17,7 @@ final class SearchableEntity { /** @var string */ - protected $indexName; + protected $indexUid; /** @var object */ protected $entity; @@ -37,20 +37,20 @@ final class SearchableEntity /** * SearchableEntity constructor. * - * @param string $indexName + * @param string $indexUid * @param object $entity * @param ClassMetadata $entityMetadata * @param object|null $normalizer * @param array $extra */ public function __construct( - string $indexName, + string $indexUid, $entity, ClassMetadata $entityMetadata, $normalizer = null, array $extra = [] ) { - $this->indexName = $indexName; + $this->indexUid = $indexUid; $this->entity = $entity; $this->entityMetadata = $entityMetadata; $this->normalizer = $normalizer; @@ -62,9 +62,9 @@ public function __construct( /** * @return string */ - public function getIndexName(): string + public function getindexUid(): string { - return $this->indexName; + return $this->indexUid; } /** diff --git a/tests/TestCase/EngineTest.php b/tests/TestCase/EngineTest.php index a7da8be7..ff96d274 100644 --- a/tests/TestCase/EngineTest.php +++ b/tests/TestCase/EngineTest.php @@ -43,7 +43,7 @@ public function testIndexingEmptyEntity() // Search try { - $this->engine->search('query', $searchableImage->getIndexName(), []); + $this->engine->search('query', $searchableImage->getIndexUid(), []); } catch (Exception $e) { $this->assertInstanceOf(ApiException::class, $e); }