You are here

function apachesolr_date_apachesolr_prepare_query in Apache Solr Search 6.2

Implementation of hook_apachesolr_prepare_query(). Adds sorts for enabled date facets to the sorting block.

File

contrib/apachesolr_date/apachesolr_date.module, line 105
Integration with the Apache Solr search application. Provides faceting for CCK Date fields.

Code

function apachesolr_date_apachesolr_prepare_query(&$query) {

  // Because we get the enabled facets just from apachesolr_search we're
  // limiting sorting to start dates.
  $enabled_facets = apachesolr_get_enabled_facets('apachesolr_search');
  $facet_definitions = apachesolr_date_apachesolr_facets();
  $facet_definitions += apachesolr_search_apachesolr_facets();
  foreach ($enabled_facets as $key => $value) {
    if (strpos($value, 'tds_cck_field_date') !== FALSE) {
      $cck_field = content_fields($facet_definitions[$key]['field_name']);
      $query
        ->set_available_sort($value, array(
        'title' => $cck_field['widget']['label'],
        // how the sort is to appear in the sorts block
        'default' => 'desc',
      ));
    }
  }
}