public function SearchApiElasticsearchBackend::getDateGranularity in Elasticsearch Connector 8.2
Same name and namespace in other branches
- 8.7 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateGranularity()
- 8 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateGranularity()
- 8.5 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateGranularity()
- 8.6 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::getDateGranularity()
Helper function to return date gap.
Parameters
$adapter:
$facet_id:
Return value
mixed|string
1 call to SearchApiElasticsearchBackend::getDateGranularity()
- SearchApiElasticsearchBackend::getDateFacetInterval in src/
Plugin/ search_api/ backend/ SearchApiElasticsearchBackend.php - Helper function which add params to date facets.
File
- src/
Plugin/ search_api/ backend/ SearchApiElasticsearchBackend.php, line 708 - Contains the SearchApiElasticsearchBackend object.
Class
- SearchApiElasticsearchBackend
- Plugin annotation @SearchApiBackend( id = "elasticsearch", label = @Translation("Elasticsearch"), description = @Translation("Index items using an Elasticsearch server.") )
Namespace
Drupal\elasticsearch_connector\Plugin\search_api\backendCode
public function getDateGranularity($adapter, $facet_id) {
// Date gaps.
$gap_weight = [
'YEAR' => 2,
'MONTH' => 1,
'DAY' => 0,
];
$gaps = [];
$date_gap = 'YEAR';
// Get the date granularity.
if (isset($adapter)) {
// Get the current date gap from the active date filters.
$active_items = $adapter
->getActiveItems([
'name' => $facet_id,
]);
if (!empty($active_items)) {
foreach ($active_items as $active_item) {
$value = $active_item['value'];
if (strpos($value, ' TO ') > 0) {
list($date_min, $date_max) = explode(' TO ', str_replace([
'[',
']',
], '', $value), 2);
$gap = self::getDateGap($date_min, $date_max, FALSE);
if (isset($gap_weight[$gap])) {
$gaps[] = $gap_weight[$gap];
}
}
}
if (!empty($gaps)) {
// Minimum gap.
$date_gap = array_search(min($gaps), $gap_weight);
}
}
}
return $date_gap;
}