You are here

protected function SearchApiElasticsearchAbstractService::getDateAggregationInterval in Search API Elasticsearch 7

Helper function which add params to date facets.

1 call to SearchApiElasticsearchAbstractService::getDateAggregationInterval()
SearchApiElasticsearchElastica::createDateFieldAggregation in modules/elastica/includes/SearchApiElasticsearchElastica.inc

File

includes/SearchApiElasticsearchAbstractService.inc, line 619
Provides a Elasticsearch-based service class for the Search API.

Class

SearchApiElasticsearchAbstractService
Elasticsearch service abstract class.

Code

protected function getDateAggregationInterval($aggregation_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, $aggregation_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;
}