Skip to content

Commit 1cad58f

Browse files
bors[bot]Holger Lösken
andauthored
Merge #69
69: Rename indexName to indexUid r=curquiza a=codedge This PR renames the `indexName` variables to `indexUid`, see #58. Co-authored-by: Holger Lösken <[email protected]>
2 parents 8c038d3 + f3f9db4 commit 1cad58f

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

src/Engine.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ public function index($searchableEntities): array
5353
continue;
5454
}
5555

56-
$indexName = $entity->getIndexName();
56+
$indexUid = $entity->getIndexUid();
5757

58-
if (!isset($data[$indexName])) {
59-
$data[$indexName] = [];
58+
if (!isset($data[$indexUid])) {
59+
$data[$indexUid] = [];
6060
}
6161

62-
$data[$indexName][] = $searchableArray + ['objectID' => $entity->getId()];
62+
$data[$indexUid][] = $searchableArray + ['objectID' => $entity->getId()];
6363
}
6464

6565
$result = [];
66-
foreach ($data as $indexName => $objects) {
67-
$result[$indexName] = $this->client
68-
->getOrCreateIndex($indexName, ['primaryKey' => 'objectID'])
66+
foreach ($data as $indexUid => $objects) {
67+
$result[$indexUid] = $this->client
68+
->getOrCreateIndex($indexUid, ['primaryKey' => 'objectID'])
6969
->addDocuments($objects);
7070
}
7171

@@ -94,19 +94,19 @@ public function remove($searchableEntities): array
9494
if (null === $searchableArray || 0 === count($searchableArray)) {
9595
continue;
9696
}
97-
$indexName = $entity->getIndexName();
97+
$indexUid = $entity->getIndexName();
9898

99-
if (!isset($data[$indexName])) {
100-
$data[$indexName] = [];
99+
if (!isset($data[$indexUid])) {
100+
$data[$indexUid] = [];
101101
}
102102

103-
$data[$indexName][] = $entity->getId();
103+
$data[$indexUid][] = $entity->getId();
104104
}
105105

106106
$result = [];
107-
foreach ($data as $indexName => $objects) {
108-
$result[$indexName] = $this->client
109-
->index($indexName)
107+
foreach ($data as $indexUid => $objects) {
108+
$result[$indexUid] = $this->client
109+
->index($indexUid)
110110
->deleteDocument(reset($objects));
111111
}
112112

@@ -117,15 +117,15 @@ public function remove($searchableEntities): array
117117
* Clear the records of an index.
118118
* This method enables you to delete an index’s contents (records).
119119
*
120-
* @param string $indexName
120+
* @param string $indexUid
121121
*
122122
* @return array
123123
*
124124
* @throws ApiException
125125
*/
126-
public function clear(string $indexName): array
126+
public function clear(string $indexUid): array
127127
{
128-
$index = $this->client->getOrCreateIndex($indexName);
128+
$index = $this->client->getOrCreateIndex($indexUid);
129129
$return = $index->deleteAllDocuments();
130130

131131
return $index->getUpdateStatus($return['updateId']);
@@ -134,44 +134,44 @@ public function clear(string $indexName): array
134134
/**
135135
* Delete an index and it's content.
136136
*
137-
* @param string $indexName
137+
* @param string $indexUid
138138
*
139139
* @return array|null
140140
*/
141-
public function delete(string $indexName): ?array
141+
public function delete(string $indexUid): ?array
142142
{
143-
return $this->client->deleteIndex($indexName);
143+
return $this->client->deleteIndex($indexUid);
144144
}
145145

146146
/**
147147
* Method used for querying an index.
148148
*
149149
* @param string $query
150-
* @param string $indexName
150+
* @param string $indexUid
151151
* @param array $searchParams
152152
*
153153
* @return array
154154
*/
155-
public function search(string $query, string $indexName, array $searchParams): array
155+
public function search(string $query, string $indexUid, array $searchParams): array
156156
{
157157
if ('' === $query) {
158158
$query = null;
159159
}
160160

161-
return $this->client->index($indexName)->rawSearch($query, $searchParams);
161+
return $this->client->index($indexUid)->rawSearch($query, $searchParams);
162162
}
163163

164164
/**
165165
* Search the index and returns the number of results.
166166
*
167167
* @param string $query
168-
* @param string $indexName
168+
* @param string $indexUid
169169
* @param array $requestOptions
170170
*
171171
* @return int
172172
*/
173-
public function count(string $query, string $indexName, array $requestOptions): int
173+
public function count(string $query, string $indexUid, array $requestOptions): int
174174
{
175-
return (int) $this->client->index($indexName)->search($query, $requestOptions)['nbHits'];
175+
return (int) $this->client->index($indexUid)->search($query, $requestOptions)['nbHits'];
176176
}
177177
}

src/SearchableEntity.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
final class SearchableEntity
1818
{
1919
/** @var string */
20-
protected $indexName;
20+
protected $indexUid;
2121

2222
/** @var object */
2323
protected $entity;
@@ -37,20 +37,20 @@ final class SearchableEntity
3737
/**
3838
* SearchableEntity constructor.
3939
*
40-
* @param string $indexName
40+
* @param string $indexUid
4141
* @param object $entity
4242
* @param ClassMetadata $entityMetadata
4343
* @param object|null $normalizer
4444
* @param array $extra
4545
*/
4646
public function __construct(
47-
string $indexName,
47+
string $indexUid,
4848
$entity,
4949
ClassMetadata $entityMetadata,
5050
$normalizer = null,
5151
array $extra = []
5252
) {
53-
$this->indexName = $indexName;
53+
$this->indexUid = $indexUid;
5454
$this->entity = $entity;
5555
$this->entityMetadata = $entityMetadata;
5656
$this->normalizer = $normalizer;
@@ -62,9 +62,9 @@ public function __construct(
6262
/**
6363
* @return string
6464
*/
65-
public function getIndexName(): string
65+
public function getindexUid(): string
6666
{
67-
return $this->indexName;
67+
return $this->indexUid;
6868
}
6969

7070
/**

tests/TestCase/EngineTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testIndexingEmptyEntity()
4343

4444
// Search
4545
try {
46-
$this->engine->search('query', $searchableImage->getIndexName(), []);
46+
$this->engine->search('query', $searchableImage->getIndexUid(), []);
4747
} catch (Exception $e) {
4848
$this->assertInstanceOf(ApiException::class, $e);
4949
}

0 commit comments

Comments
 (0)