From 44f03d7c76ea60f263d336a50648532a9bb3d42d Mon Sep 17 00:00:00 2001 From: melaniekung Date: Thu, 9 Jan 2025 10:17:58 -0800 Subject: [PATCH] ES 6.x Updates --- .../modules/search/actions/autocompleteAction.class.php | 2 +- lib/job/arUpdateEsActorRelationsJob.class.php | 4 +++- lib/model/QubitInformationObject.php | 6 +++--- lib/task/search/arDocumentTask.class.php | 6 ++++-- .../lib/arElasticSearchPlugin.class.php | 5 +++++ .../lib/arElasticSearchPluginQuery.class.php | 2 +- 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/apps/qubit/modules/search/actions/autocompleteAction.class.php b/apps/qubit/modules/search/actions/autocompleteAction.class.php index 02e9447828..101858a782 100644 --- a/apps/qubit/modules/search/actions/autocompleteAction.class.php +++ b/apps/qubit/modules/search/actions/autocompleteAction.class.php @@ -86,7 +86,7 @@ public function execute($request) $queryBool = new \Elastica\Query\BoolQuery(); // Match in autocomplete - $queryText = new \Elastica\Query\Match(); + $queryText = new \Elastica\Query\MatchQuery(); $queryText->setFieldQuery($item['field'].'.autocomplete', $this->queryString); $queryBool->addMust($queryText); diff --git a/lib/job/arUpdateEsActorRelationsJob.class.php b/lib/job/arUpdateEsActorRelationsJob.class.php index 941678cbc4..041521479b 100644 --- a/lib/job/arUpdateEsActorRelationsJob.class.php +++ b/lib/job/arUpdateEsActorRelationsJob.class.php @@ -101,8 +101,10 @@ public static function updateActorRelationships($actor) public static function previousRelationActorIds($actorId) { try { + // Dummy type is needed for ES 6, this should be updated in ES 7.x when type is not required for getDocument() + $esType = QubitSearch::getInstance()->getEsType(); // Get actor's previously indexed relations from Elasticsearch - $doc = QubitSearch::getInstance()->index->getIndex('QubitActor')->getDocument($actorId); + $doc = QubitSearch::getInstance()->index->getIndex('QubitActor')->getType($esType)->getDocument($actorId); return self::uniqueIdsFromRelationData($doc->getData()['actorRelations']); } catch (\Elastica\Exception\NotFoundException $e) { diff --git a/lib/model/QubitInformationObject.php b/lib/model/QubitInformationObject.php index 17da4ff220..72d980dbf3 100644 --- a/lib/model/QubitInformationObject.php +++ b/lib/model/QubitInformationObject.php @@ -2171,14 +2171,14 @@ public static function getByTitleIdentifierAndRepo($identifier, $title, $repoNam $queryBool = new \Elastica\Query\BoolQuery(); // Use match query for exact matches. - $queryText = new \Elastica\Query\Match(); + $queryText = new \Elastica\Query\MatchQuery(); $queryBool->addMust($queryText->setFieldQuery('identifier', $identifier)); - $queryText = new \Elastica\Query\Match(); + $queryText = new \Elastica\Query\MatchQuery(); $queryBool->addMust($queryText->setFieldQuery(sprintf('i18n.%s.title.untouched', $currentCulture), $title)); if (null !== $repoName) { - $queryText = new \Elastica\Query\Match(); + $queryText = new \Elastica\Query\MatchQuery(); $queryBool->addMust($queryText->setFieldQuery(sprintf('repository.i18n.%s.authorizedFormOfName.untouched', $currentCulture), $repoName)); } diff --git a/lib/task/search/arDocumentTask.class.php b/lib/task/search/arDocumentTask.class.php index 11528b48f7..78e02c5dce 100644 --- a/lib/task/search/arDocumentTask.class.php +++ b/lib/task/search/arDocumentTask.class.php @@ -34,10 +34,12 @@ public function execute($arguments = [], $options = []) { parent::execute($arguments, $options); - if (null !== $slugObject = QubitObject::getBySlug($arguments[slug])) { + if (null !== $slugObject = QubitObject::getBySlug($arguments['slug'])) { $this->log(sprintf("Fetching data for %s ID %d...\n", $slugObject->className, $slugObject->id)); - $doc = QubitSearch::getInstance()->index->getIndex($slugObject->className)->getDocument($slugObject->id); + // Dummy type is needed for ES 6, this should be updated in ES 7.x when type is not required for getDocument() + $esType = QubitSearch::getInstance()->getEsType(); + $doc = QubitSearch::getInstance()->index->getIndex($slugObject->className)->getType($esType)->getDocument($slugObject->id); echo json_encode($doc->getData(), JSON_PRETTY_PRINT)."\n"; } else { diff --git a/plugins/arElasticSearchPlugin/lib/arElasticSearchPlugin.class.php b/plugins/arElasticSearchPlugin/lib/arElasticSearchPlugin.class.php index 0170ba146e..14ac780c83 100644 --- a/plugins/arElasticSearchPlugin/lib/arElasticSearchPlugin.class.php +++ b/plugins/arElasticSearchPlugin/lib/arElasticSearchPlugin.class.php @@ -502,6 +502,11 @@ public static function modelClassFromQubitObjectClass($className) return str_replace('Qubit', 'arElasticSearch', $className); } + public function getEsType() + { + return self::ES_TYPE; + } + /** * Initialize indices wrapper. */ diff --git a/plugins/arElasticSearchPlugin/lib/arElasticSearchPluginQuery.class.php b/plugins/arElasticSearchPlugin/lib/arElasticSearchPluginQuery.class.php index 5f3bf66a18..b044f0b33a 100644 --- a/plugins/arElasticSearchPlugin/lib/arElasticSearchPluginQuery.class.php +++ b/plugins/arElasticSearchPlugin/lib/arElasticSearchPluginQuery.class.php @@ -114,7 +114,7 @@ public function addAggFilters($aggs, $params) if ('collection' == $param) { $collection = QubitInformationObject::getById($value); - $querySelf = new \Elastica\Query\Match(); + $querySelf = new \Elastica\Query\MatchQuery(); $querySelf->setFieldQuery('slug', $collection->slug); $queryBool = new \Elastica\Query\BoolQuery();