You are here

protected function SearchApiElasticsearchConnector::addFacetOptions in Elasticsearch Connector 7

Helper function that add options and return facet

1 call to SearchApiElasticsearchConnector::addFacetOptions()
SearchApiElasticsearchConnector::addSearchFacets in modules/elasticsearch_connector_search_api/service.inc
Helper function build facets in search.

File

modules/elasticsearch_connector_search_api/service.inc, line 1745
Provides a Elasticsearch-based service class for the Search API using Elasticsearch Connector module.

Class

SearchApiElasticsearchConnector
Search service class.

Code

protected function addFacetOptions(&$facet, SearchApiQueryInterface $query, $facet_info) {
  $facet_limit = $this
    ->getFacetLimit($facet_info);
  $facet_search_filter = $this
    ->getFacetSearchFilter($query, $facet_info);

  // Set the field.
  $facet[$facet_info['facet_type']]['field'] = $facet_info['field'];

  // OR facet. We remove filters affecting the assiociated field.
  // TODO: distinguish between normal filters and facet filters.
  // See http://drupal.org/node/1390598.
  // Filter the facet.
  if (!empty($facet_search_filter)) {
    $facet['facet_filter'] = $facet_search_filter;
  }

  // Limit the number of returned entries.
  if ($facet_limit > 0 && $facet_info['facet_type'] == 'terms') {
    $facet[$facet_info['facet_type']]['size'] = $facet_limit;
  }
  return $facet;
}