You are here

function apachesolr_search_add_facet_params in Apache Solr Search 6

Same name and namespace in other branches
  1. 5.2 apachesolr_search.module \apachesolr_search_add_facet_params()
  2. 6.2 apachesolr_search.module \apachesolr_search_add_facet_params()
1 call to apachesolr_search_add_facet_params()
apachesolr_search_execute in ./apachesolr_search.module
Execute a search results based on keyword, filter, and sort strings.

File

./apachesolr_search.module, line 288
Provides a content search implementation for node content for use with the Apache Solr search application.

Code

function apachesolr_search_add_facet_params(&$params, $query) {
  $facet_query_limits = variable_get('apachesolr_facet_query_limits', array());
  $facet_missing = variable_get('apachesolr_facet_missing', array());
  foreach (apachesolr_get_enabled_facets() as $module => $module_facets) {
    if (!module_exists($module)) {

      // When modules are disabled their facet settings may remain.
      continue;
    }
    foreach ($module_facets as $delta => $facet_field) {

      // TODO: generalize handling of date and range facets.
      if ($module == 'apachesolr_search' && ($facet_field == 'created' || $facet_field == 'changed')) {
        list($start, $end, $gap) = apachesolr_search_date_range($query, $facet_field);
        if ($gap) {
          $params['facet.date'][] = $facet_field;
          $params['f.' . $facet_field . '.facet.date.start'] = $start;
          $params['f.' . $facet_field . '.facet.date.end'] = $end;
          $params['f.' . $facet_field . '.facet.date.gap'] = $gap;
        }
      }
      else {
        $params['facet.field'][] = $facet_field;

        // Facet limits
        if (isset($facet_query_limits[$module][$delta])) {
          $params['f.' . $facet_field . '.facet.limit'] = $facet_query_limits[$module][$delta];
        }

        // Facet missing
        if (!empty($facet_missing[$module][$delta])) {
          $params['f.' . $facet_field . '.facet.missing'] = 'true';
        }
      }
    }
  }
  if (!empty($params['facet.field'])) {

    // Add a default limit for fields where no limit was set.
    $params['facet.limit'] = variable_get('apachesolr_facet_query_limit_default', 20);
  }
}