Skip to content

Commit

Permalink
Add setType method to arSolrQuery
Browse files Browse the repository at this point in the history
Added a setType method to arSolrQuery which appends the provided type to
each of the search fields.
  • Loading branch information
anvit committed Jun 18, 2024
1 parent f78050c commit da343ae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/task/search/arSolrSearchTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down
3 changes: 2 additions & 1 deletion plugins/arSolrPlugin/lib/arSolrPlugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions plugins/arSolrPlugin/lib/query/arSolrQuery.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit da343ae

Please sign in to comment.