You are here

protected function SearchApiElasticsearchBackend::getDateFacetInterval in Elasticsearch Connector 8.7

Same name and namespace in other branches
  1. 8 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateFacetInterval()
  2. 8.2 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateFacetInterval()
  3. 8.5 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateFacetInterval()
  4. 8.6 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateFacetInterval()

Helper function which add params to date facets.

Parameters

mixed $facet_id: The facet id parameter.

Return value

string Returns facet interval.

1 call to SearchApiElasticsearchBackend::getDateFacetInterval()
SearchApiElasticsearchBackend::createDateFieldFacet in src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php
Helper function create Facet for date field type.

File

src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php, line 1006

Class

SearchApiElasticsearchBackend
Elasticsearch Search API Backend definition.

Namespace

Drupal\elasticsearch_connector\Plugin\search_api\backend

Code

protected function getDateFacetInterval($facet_id) {

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

  // Get the FacetApiAdapter 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;
}