You are here

protected function SarniaSolrService::preQuery in Sarnia 7

Alter the query built by SearchApiSolrService::search().

Sarnia needs to avoid making assumptions about the Solr configuration and schema (solrconfig.xml and schema.xml) since the point is to read arbitrary Solr cores.

Overrides SearchApiSolrService::preQuery

File

./service.inc, line 127

Class

SarniaSolrService
Search service class using Solr server.

Code

protected function preQuery(array &$call_args, SearchApiQueryInterface $query) {
  if (!isset($call_args['query']) || empty($call_args['query'])) {
    $call_args['query'] = $this->options['sarnia_default_query'];
  }

  // Remove the Search API index id filter and the hash.
  foreach ($call_args['params']['fq'] as $index => $value) {
    list($filter, $val) = explode(':', $value);
    if (in_array($filter, array(
      'hash',
      'index_id',
    ))) {
      unset($call_args['params']['fq'][$index]);
    }
  }
  $call_args['params']['fq'] = array_values($call_args['params']['fq']);

  // Make sure that all fields, plus the score, are returned in Solr results.
  $call_args['params']['fl'] = array(
    '*,score',
  );

  // Use the admin-defined requestHandler for the query type.
  if (!empty($this->options['sarnia_request_handler'])) {
    $call_args['params']['qt'] = $this->options['sarnia_request_handler'];
  }
}