From da343ae6ddb6a304cd8e8df781ed9e36e971f3aa Mon Sep 17 00:00:00 2001 From: Anvit Srivastav Date: Tue, 18 Jun 2024 15:45:34 -0700 Subject: [PATCH] Add setType method to arSolrQuery Added a setType method to arSolrQuery which appends the provided type to each of the search fields. --- lib/task/search/arSolrSearchTask.class.php | 2 +- plugins/arSolrPlugin/lib/arSolrPlugin.class.php | 3 ++- plugins/arSolrPlugin/lib/query/arSolrQuery.class.php | 8 ++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/task/search/arSolrSearchTask.class.php b/lib/task/search/arSolrSearchTask.class.php index 7a5c122c66..b290fcd6da 100644 --- a/lib/task/search/arSolrSearchTask.class.php +++ b/lib/task/search/arSolrSearchTask.class.php @@ -94,7 +94,7 @@ private function runSolrQuery($solrInstance, $queryText, $rows, $start, $fields) $query->setFields(arSolrPluginUtil::getBoostedSearchFields($newFields)); } - $docs = $solrInstance->search($query); + $docs = $solrInstance->search($query, 'QubitInformationObject'); if ($docs) { foreach ($docs as $resp) { $this->log(sprintf('%s - %s', $resp->id, $resp->{'i18n.en.title'}[0])); diff --git a/plugins/arSolrPlugin/lib/arSolrPlugin.class.php b/plugins/arSolrPlugin/lib/arSolrPlugin.class.php index ee05ad8f7d..bb63e2f97b 100644 --- a/plugins/arSolrPlugin/lib/arSolrPlugin.class.php +++ b/plugins/arSolrPlugin/lib/arSolrPlugin.class.php @@ -276,9 +276,10 @@ public function getSolrCollection() return $this->solrClientOptions['collection']; } - public function search($query) + public function search($query, $type) { $url = $this->getSolrUrl().'/solr/'.$this->getSolrCollection().'/query'; + $query->setType($type); $response = arSolrPlugin::makeHttpRequest($url, 'POST', json_encode($query->getQueryParams())); return $response->response->docs; diff --git a/plugins/arSolrPlugin/lib/query/arSolrQuery.class.php b/plugins/arSolrPlugin/lib/query/arSolrQuery.class.php index f194d2e44f..afe64502e7 100644 --- a/plugins/arSolrPlugin/lib/query/arSolrQuery.class.php +++ b/plugins/arSolrPlugin/lib/query/arSolrQuery.class.php @@ -166,4 +166,12 @@ public function addAggregation($agg): self return $this; } + + public function setType($type) { + $newFieldsArr = []; + foreach ($this->fields as $field) { + array_push($newFieldsArr, "{$type}.{$field}"); + } + $this->setFields($newFieldsArr); + } }