protected function SearchApiElasticsearchBackend::parseSearchFacets in Elasticsearch Connector 8.5
Same name and namespace in other branches
- 8.7 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::parseSearchFacets()
- 8 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::parseSearchFacets()
- 8.2 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::parseSearchFacets()
- 8.6 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::parseSearchFacets()
Helper function that parse facets.
Parameters
array $response:
QueryInterface $query:
Return value
array
File
- src/
Plugin/ search_api/ backend/ SearchApiElasticsearchBackend.php, line 1064
Class
- SearchApiElasticsearchBackend
- Elasticsearch Search API Backend definition.
Namespace
Drupal\elasticsearch_connector\Plugin\search_api\backendCode
protected function parseSearchFacets(array $response, QueryInterface $query) {
$result = [];
$index_fields = $this
->getIndexFields($query);
$facets = $query
->getOption('search_api_facets');
if (!empty($facets) && isset($response['facets'])) {
foreach ($response['facets'] as $facet_id => $facet_data) {
if (isset($facets[$facet_id])) {
$facet_info = $facets[$facet_id];
$facet_min_count = $facet_info['min_count'];
$field_id = $facet_info['field'];
$field_type = search_api_extract_inner_type($index_fields[$field_id]['type']);
// TODO: handle different types (GeoDistance and so on).
if ($field_type === 'date') {
foreach ($facet_data['entries'] as $entry) {
if ($entry['count'] >= $facet_min_count) {
// Divide time by 1000 as we want seconds from epoch
// not milliseconds.
$result[$facet_id][] = [
'count' => $entry['count'],
'filter' => '"' . $entry['time'] / 1000 . '"',
];
}
}
}
else {
foreach ($facet_data['terms'] as $term) {
if ($term['count'] >= $facet_min_count) {
$result[$facet_id][] = [
'count' => $term['count'],
'filter' => '"' . $term['term'] . '"',
];
}
}
}
}
}
}
return $result;
}