You are here

function apachesolr_proximity_apachesolr_query_alter in Apache Solr Term Proximity 7

Same name and namespace in other branches
  1. 6.3 apachesolr_proximity.apachesolr.inc \apachesolr_proximity_apachesolr_query_alter()

Implements hook_apachesolr_query_alter().

File

./apachesolr_proximity.apachesolr.inc, line 11
Implementation of Apache Solr Search Integration hooks.

Code

function apachesolr_proximity_apachesolr_query_alter($query) {
  $env_id = $query
    ->solr('getId');
  $boost = apachesolr_proximity_get_boost($env_id);

  // Parse terms and phrases. If less than two keyowrds or phrases are found, do
  // not do anything since proximity boosting wouldn't make sense.
  $q = $query
    ->getParam('q');
  $parsed = apachesolr_proximity_parse_query($q);
  if (count($parsed) > 1) {

    // Get the operator, defaults to OR.
    $operator = $query
      ->getParam('q.op');
    if (!$operator) {
      $operator = 'OR';
    }

    // Replace the "q" param with the query containing the proximity boost. We
    // have to use the edismax request handler to support proximity queries.
    $q = apachesolr_proximity_build_query($q, $operator, $parsed, $boost);
    $query
      ->replaceParam('q', $q);
    $query
      ->replaceParam('defType', 'edismax');
  }
}