You are here

apachesolr_views.module in Apache Solr Views 7

Same filename and directory in other branches
  1. 6 apachesolr_views.module

Provides Views Implementation for the ApacheSolr Search Integration project drupal.org/project/apachesolr

File

apachesolr_views.module
View source
<?php

/**
 * @file
 * Provides Views Implementation for the ApacheSolr Search Integration project
 * drupal.org/project/apachesolr
 */

/**
 * Implements of hook_views_api().
 */
function apachesolr_views_views_api() {
  return array(
    'api' => '3.0',
  );
}

/**
 * Implements hook_views_query_alter().
 */
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);
    }
  }
}