Skip to content

Rename indexName to indexUid #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions src/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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));
}

Expand All @@ -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']);
Expand All @@ -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'];
}
}
12 changes: 6 additions & 6 deletions src/SearchableEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
final class SearchableEntity
{
/** @var string */
protected $indexName;
protected $indexUid;

/** @var object */
protected $entity;
Expand All @@ -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;
Expand All @@ -62,9 +62,9 @@ public function __construct(
/**
* @return string
*/
public function getIndexName(): string
public function getindexUid(): string
{
return $this->indexName;
return $this->indexUid;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/EngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down