You are here

function facetapi_luceneapi_facetapi_query_date_process in Facet API 6

Implementation of hook_facetapi_query_TYPE_process().

File

contrib/facetapi_luceneapi/facetapi_luceneapi.module, line 197
The Search Lucene API module's implementation of the the Facet API.

Code

function facetapi_luceneapi_facetapi_query_date_process(FacetapiAdapter $adapter, array $facet, Zend_Search_Lucene_Search_Query $query) {
  $values = $adapter
    ->getActiveFacets($facet['field alias']);
  if (empty($values)) {
    return;
  }
  try {

    // Gets the facet's operator.
    if (!($boolean = luceneapi_query_get('boolean'))) {
      throw new Exception(t('Error instantiating boolean query.'));
    }
    foreach ($values as $value => $filter_string) {
      $range = explode(' TO ', trim($value, '{[]}'));

      // Adds subquery if ranges were extracted.
      if (2 == count($range)) {
        $range = array_map('strtotime', $range);
        if ($subquery = luceneapi_query_get('range', $range[0], $range[1], FALSE, $facet['field'])) {
          luceneapi_subquery_add($boolean, $subquery, 'required', TRUE);
        }
      }
    }

    // Makes query irrelevant in scoring, appends subquery.
    $boolean
      ->setBoost(LUCENEAPI_IRRELEVANT);
    luceneapi_subquery_add($query, $boolean, 'required');
  } catch (Exception $e) {
    luceneapi_throw_error($e, WATCHDOG_ERROR, 'facetapi_luceneapi');
  }
}