protected function SearchApiElasticsearchConnector::parseSearchFacets in Elasticsearch Connector 7
Same name and namespace in other branches
- 7.5 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::parseSearchFacets()
- 7.2 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::parseSearchFacets()
Helper function that parse facets.
1 call to SearchApiElasticsearchConnector::parseSearchFacets()
- SearchApiElasticsearchConnector::parseSearchResponse in modules/
elasticsearch_connector_search_api/ service.inc - Helper function which parse facets in search().
File
- modules/
elasticsearch_connector_search_api/ service.inc, line 1933 - Provides a Elasticsearch-based service class for the Search API using Elasticsearch Connector module.
Class
- SearchApiElasticsearchConnector
- Search service class.
Code
protected function parseSearchFacets($response, SearchApiQueryInterface $query) {
$result = array();
$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][] = array(
'count' => $entry['count'],
'filter' => '"' . $entry['time'] / 1000 . '"',
);
}
}
}
else {
foreach ($facet_data['terms'] as $term) {
if ($term['count'] >= $facet_min_count) {
if ($field_type == 'boolean') {
$term_value = $term['term'] == 'T' ? TRUE : FALSE;
}
else {
$term_value = '"' . $term['term'] . '"';
}
$result[$facet_id][] = array(
'count' => $term['count'],
'filter' => $term_value,
);
}
}
}
}
}
}
return $result;
}