protected function SearchApiElasticsearchConnector::addSearchFacets in Elasticsearch Connector 7
Same name and namespace in other branches
- 7.5 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::addSearchFacets()
- 7.2 modules/elasticsearch_connector_search_api/service.inc \SearchApiElasticsearchConnector::addSearchFacets()
Helper function build facets in search.
1 call to SearchApiElasticsearchConnector::addSearchFacets()
- SearchApiElasticsearchConnector::search in modules/
elasticsearch_connector_search_api/ service.inc - Overrides search().
File
- modules/
elasticsearch_connector_search_api/ service.inc, line 1702 - Provides a Elasticsearch-based service class for the Search API using Elasticsearch Connector module.
Class
- SearchApiElasticsearchConnector
- Search service class.
Code
protected function addSearchFacets(array &$params, SearchApiQueryInterface $query) {
// SEARCH API FACETS.
$facets = $query
->getOption('search_api_facets');
$index_fields = $this
->getIndexFields($query);
if (!empty($facets)) {
// Loop trough facets.
$elasticsearch_facets = array();
foreach ($facets as $facet_id => $facet_info) {
$field_id = $facet_info['field'];
$facet = array(
$field_id => array(),
);
// Skip if not recognized as a known field.
if (!isset($index_fields[$field_id])) {
continue;
}
$field_type = search_api_extract_inner_type($index_fields[$field_id]['type']);
// TODO: handle different types (GeoDistance and so on). See the supportedFeatures todo.
if ($field_type === 'date') {
$facet_type = 'date_histogram';
$facet[$field_id] = $this
->createDateFieldFacet($field_id, $facet);
}
else {
$facet_type = 'terms';
$facet[$field_id][$facet_type]['all_terms'] = (bool) $facet_info['missing'];
}
// Add the facet.
if (!empty($facet[$field_id])) {
// Add facet options
$facet_info['facet_type'] = $facet_type;
$facet[$field_id] = $this
->addFacetOptions($facet[$field_id], $query, $facet_info);
}
$params['body']['facets'][$field_id] = $facet[$field_id];
}
}
}