You are here

protected function SearchApiAcquiaSearchService::preQuery in Acquia Search for Search API 7

Same name and namespace in other branches
  1. 7.2 includes/SearchApiAcquiaSearchService.php \SearchApiAcquiaSearchService::preQuery()

Overrides SearchApiSolrService::preQuery().

Sets the eDisMax parameters if certain conditions are met, adds the default parameters that are usually set in Search API's solrconfig.xml file.

Overrides SearchApiSolrService::preQuery

File

includes/SearchApiAcquiaSearchService.php, line 201
Contains SearchApiAcquiaSearchService.

Class

SearchApiAcquiaSearchService
Search API service class for Acquia Search.

Code

protected function preQuery(array &$call_args, SearchApiQueryInterface $query) {
  $params =& $call_args['params'];

  // Bails if this is a 'mlt' query or something else custom.
  if (!empty($params['qt']) || !empty($params['defType'])) {
    return;
  }

  // The Search API module adds default "fl" parameters in solrconfig.xml
  // that are not present in Acquia Search's solrconfig.xml file. Add them
  // and others here as a backwards compatible solution.
  // @see http://drupal.org/node/1619770
  $params += array(
    'echoParams' => 'none',
    'fl' => 'item_id,score',
    'q.op' => 'AND',
    'q.alt' => '*:*',
    'spellcheck' => 'false',
    'spellcheck.onlyMorePopular' => 'true',
    'spellcheck.extendedResults' => 'false',
    'spellcheck.count' => '1',
    'hl' => 'false',
    'hl.fl' => 'spell',
    'hl.simple.pre' => '[HIGHLIGHT]',
    'hl.simple.post' => '[/HIGHLIGHT]',
    'hl.snippets' => '3',
    'hl.fragsize' => '70',
    'hl.mergeContiguous' => 'true',
  );

  // Set the qt to eDisMax if we have keywords and either the configuration
  // is set to always use eDisMax or the keys contain a wildcard (* or ?).
  $keys = $query
    ->getOriginalKeys();
  if ($keys && (($wildcard = preg_match('/\\S+[*?]/', $keys)) || $this->options['edismax'])) {
    $params['defType'] = 'edismax';
    if ($wildcard) {

      // Converts keys to lower case, reset keys in query and replaces param.
      $new_keys = preg_replace_callback('/(\\S+[*?]\\S*)/', array(
        $this,
        'toLower',
      ), $keys);
      $query
        ->keys($new_keys);
      $call_args['query'] = $new_keys;
    }
  }
}