You are here

protected function SearchApiElasticsearchBackend::addFacetOptions in Elasticsearch Connector 8.6

Same name and namespace in other branches
  1. 8.7 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::addFacetOptions()
  2. 8 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::addFacetOptions()
  3. 8.2 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::addFacetOptions()
  4. 8.5 src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php \Drupal\elasticsearch_connector\Plugin\search_api\backend\SearchApiElasticsearchBackend::addFacetOptions()

Helper function that adds options and returns facet.

Parameters

array $facet:

QueryInterface $query:

string $facet_info:

Return value

array

1 call to SearchApiElasticsearchBackend::addFacetOptions()
SearchApiElasticsearchBackend::addSearchFacets in src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php
Helper function build facets in search.

File

src/Plugin/search_api/backend/SearchApiElasticsearchBackend.php, line 897

Class

SearchApiElasticsearchBackend
Elasticsearch Search API Backend definition.

Namespace

Drupal\elasticsearch_connector\Plugin\search_api\backend

Code

protected function addFacetOptions(array &$facet, QueryInterface $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 associated 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;
}