You are here

function acquia_search_apachesolr_query_alter in Acquia Connector 7.3

Same name and namespace in other branches
  1. 7 acquia_search/acquia_search.module \acquia_search_apachesolr_query_alter()
  2. 7.2 acquia_search/acquia_search.module \acquia_search_apachesolr_query_alter()

Implements hook_apachesolr_modify_query().

Possibly alters the query type ('defType') param to edismax.

File

acquia_search/acquia_search.module, line 925
Integration between Acquia Drupal and Acquia's hosted solr search service.

Code

function acquia_search_apachesolr_query_alter($query) {
  $environment = apachesolr_environment_load($query
    ->solr('getId'));

  // @todo - does it make sense to check $caller too?
  if (!acquia_search_environment_connected($environment) || $query
    ->getParam('qt') || $query
    ->getParam('defType')) {

    // This is a 'mlt' query or something else custom.
    return;
  }

  // Set the qt to edismax if we have keywords, and we always use it, or are
  // using a wildcard (* or ?).
  $keys = $query
    ->getParam('q');
  if ($keys && (($wildcard = preg_match('/\\S+[*?]/', $keys)) || variable_get('acquia_search_edismax_default', 0))) {
    $query
      ->addParam('defType', 'edismax');
    if ($wildcard) {
      $keys = preg_replace_callback('/(\\S+[*?]\\S*)/', '_acquia_search_lower', $keys);
      $query
        ->replaceParam('q', $keys);
    }
  }
  if ($environment['service_class'] === AcquiaSearchSolrService::class) {

    // Converts qf parameter to required format.
    $qf = $query
      ->getParam('qf');
    if (!empty($qf) && is_array($qf)) {
      $qf_string = implode(' ', $qf);
      $query
        ->replaceParam('qf', $qf_string);
    }
  }
}