Skip to content

Commit c6f0c2a

Browse files
committed
Fix autocompleteAction bug, address CR feedback
Fix bug in search autocompleteAction which was showing duplicate results for actors under repositories. Also address some of the CR feedback and update/add methods for add, update, and deleteById in the arElasticSearchMultiIndexWrapper.
1 parent fc6d069 commit c6f0c2a

File tree

4 files changed

+21
-14
lines changed

4 files changed

+21
-14
lines changed

apps/qubit/modules/search/actions/autocompleteAction.class.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public function execute($request)
3939
$culture = $this->context->user->getCulture();
4040

4141
$client = QubitSearch::getInstance()->client;
42-
$indices = QubitSearch::getInstance()->index->getIndices();
4342

4443
// Multisearch object
4544
$mSearch = new \Elastica\Multi\Search($client);
@@ -76,12 +75,8 @@ public function execute($request)
7675

7776
foreach ($items as $item) {
7877
$search = new \Elastica\Search($client);
79-
foreach ($indices as $type => $index) {
80-
$elasticSearchTypeName = QubitSearch::getInstance()::ES_TYPE;
81-
82-
// This can be updated in ES 7.x when type params are optional
83-
$search->addIndex($index)->addType($index->getType($elasticSearchTypeName));
84-
}
78+
$indexWrapper = QubitSearch::getInstance()->index;
79+
$search->addIndex($indexWrapper->getIndex($item['type']));
8580

8681
$query = new \Elastica\Query();
8782
$query->setSize(3)->setSource($item['fields']);

lib/QubitLftSyncer.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private function repairEsChildrenLftValues()
9292
$results = QubitPdo::fetchAll($sql, $params, ['fetchMode' => PDO::FETCH_ASSOC]);
9393

9494
$bulk = new Elastica\Bulk(QubitSearch::getInstance()->client);
95-
$bulk->setIndex(QubitSearch::getInstance()->index->getIndex('QubitInformationObject')->getName());
95+
$bulk->setIndex(QubitSearch::getInstance()->index->getIndex('QubitInformationObject'));
9696
$bulk->setType(QubitSearch::getInstance()::ES_TYPE);
9797

9898
foreach ($results as $row) {

plugins/arElasticSearchPlugin/lib/arElasticSearchMultiIndexWrapper.class.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
* and has methods that match signatures of pre ES 6.x methods that used a
2323
* single index with multiple types instead of multiple index with a single
2424
* type or no type.
25+
* This class has an indices property which is an array of ElasticSearch
26+
* indices in order to keep arElasticSearchPlugin's index property backwards
27+
* compatible with custom themes.
2528
*/
2629
class arElasticSearchMultiIndexWrapper
2730
{
@@ -54,6 +57,16 @@ public function deleteDocuments($name, $documents)
5457
$this->indices[$name]->deleteDocuments($documents);
5558
}
5659

60+
public function updateDocuments($name, $documents)
61+
{
62+
$this->indices[$name]->updateDocuments($documents);
63+
}
64+
65+
public function deleteById($name, $documentId)
66+
{
67+
$this->indices[$name]->deleteById($documentId);
68+
}
69+
5770
public function refresh()
5871
{
5972
foreach ($this->indices as $index) {

plugins/arElasticSearchPlugin/lib/arElasticSearchPlugin.class.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public function addDocument($data, $indexName)
385385
$this->index->refresh();
386386
}
387387
} else {
388-
$this->index->getIndex($indexName)->addDocuments([$document]);
388+
$this->index->addDocuments($indexName, [$document]);
389389
}
390390
}
391391

@@ -418,7 +418,7 @@ public function partialUpdate($object, $data)
418418
$document->setType(self::ES_TYPE);
419419

420420
try {
421-
$this->index->getIndex($indexName)->updateDocuments([$document]);
421+
$this->index->updateDocuments($indexName, [$document]);
422422
} catch (\Elastica\Exception\NotFoundException $e) {
423423
// Create document if it's not found
424424
$this->update($object);
@@ -438,7 +438,7 @@ public function partialUpdateById(string $className, int $id, array $data)
438438
$document = new \Elastica\Document($id, $data);
439439

440440
try {
441-
$this->index->getIndex($className)->updateDocuments([$document]);
441+
$this->index->updateDocuments($className, [$document]);
442442
} catch (\Elastica\Exception\ResponseException $e) {
443443
// Create document if none exists
444444
$modelPdoClassName = self::modelClassFromQubitObjectClass($className).'Pdo';
@@ -462,9 +462,8 @@ public function delete($object)
462462
return;
463463
}
464464

465+
$indexName = get_class($object);
465466
if ($this->batchMode) {
466-
$indexName = get_class($object);
467-
468467
if (!$this->currentBatchIndexName) {
469468
$this->currentBatchIndexName = $indexName;
470469
}
@@ -491,7 +490,7 @@ public function delete($object)
491490
}
492491
} else {
493492
try {
494-
$this->index->getIndex($indexName)->deleteById($object->id);
493+
$this->index->deleteById($indexName, $object->id);
495494
} catch (\Elastica\Exception\NotFoundException $e) {
496495
// Ignore
497496
}

0 commit comments

Comments
 (0)