You are here

protected function SearchApiElasticsearchConnector::getDateFacetInterval in Elasticsearch Connector 7.2

Same name and namespace in other branches
  1. 7.5 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::getDateFacetInterval()
  2. 7 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::getDateFacetInterval()

Helper function which add params to date facets.

1 call to SearchApiElasticsearchConnector::getDateFacetInterval()
SearchApiElasticsearchConnector::addSearchFacets in modules/elasticsearch_connector_search_api/service.inc
Helper function build facets in search.

File

modules/elasticsearch_connector_search_api/service.inc, line 1823
Provides a Elasticsearch-based service class for the Search API using Elasticsearch Connector module.

Class

SearchApiElasticsearchConnector
Search service class.

Code

protected function getDateFacetInterval($facet_id) {

  // Active search corresponding to this index.
  $searcher = key(facetapi_get_active_searchers());

  // Get the FacetApiAdpater for this searcher.
  $adapter = isset($searcher) ? facetapi_adapter_load($searcher) : NULL;

  // Get the date granularity.
  $date_gap = $this
    ->getDateGranularity($adapter, $facet_id);
  switch ($date_gap) {

    // Already a selected YEAR, we want the months.
    case 'YEAR':
      $date_interval = 'month';
      break;

    // Already a selected MONTH, we want the days.
    case 'MONTH':
      $date_interval = 'day';
      break;

    // Already a selected DAY, we want the hours and so on.
    case 'DAY':
      $date_interval = 'hour';
      break;

    // By default we return result counts by year.
    default:
      $date_interval = 'year';
  }
  return $date_interval;
}