You are here

function apachesolr_views_views_query_alter in Apache Solr Views 7

Implements hook_views_query_alter().

File

./apachesolr_views.module, line 19
Provides Views Implementation for the ApacheSolr Search Integration project drupal.org/project/apachesolr

Code

function apachesolr_views_views_query_alter($view, $query) {
  if (get_class($query) == 'apachesolr_views_query' && isset($view->fields['snippet'])) {

    // Add additional parameters to get snippet.
    // @see apachesolr_search_highlighting_params().
    $params['hl'] = variable_get('apachesolr_hl_active', NULL);
    $params['hl.fragsize'] = variable_get('apachesolr_hl_textsnippetlength', NULL);
    $params['hl.simple.pre'] = variable_get('apachesolr_hl_pretag', NULL);
    $params['hl.simple.post'] = variable_get('apachesolr_hl_posttag', NULL);
    $params['hl.snippets'] = variable_get('apachesolr_hl_numsnippets', NULL);

    // This should be an array of possible field names.
    $params['hl.fl'] = variable_get('apachesolr_hl_fieldtohighlight', NULL);
    $params = array_filter($params);
    foreach ($params as $key => $value) {
      $view->query
        ->add_parameter($key, $value);
    }
  }
}