You are here

protected function SearchApiElasticsearchElastica::addAggregationOptions in Search API Elasticsearch 7

Helper function that add options and return Aggregation.

1 call to SearchApiElasticsearchElastica::addAggregationOptions()
SearchApiElasticsearchElastica::addSearchAggregation in modules/elastica/includes/SearchApiElasticsearchElastica.inc
Helper function build Aggregations in search.

File

modules/elastica/includes/SearchApiElasticsearchElastica.inc, line 733
Provides Elastica client for Search API Elasticsearch.

Class

SearchApiElasticsearchElastica
Search API Elasticsearch Elastica service class.

Code

protected function addAggregationOptions(&$facet, SearchApiQueryInterface $query, $facet_info, Elastica\Query $elastica_query, $field_type) {
  $facet_limit = $this
    ->getAggregationLimit($facet_info);
  $facet_search_filter = $this
    ->getAggregationSearchFilter($query, $facet_info);

  // Set the field.
  $facet
    ->setField($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)) {
    $aggrFilter = new \Elastica\Aggregation\Filter($facet_info['field']);
    $aggr = new \Elastica\Aggregation\Range($facet_info['field']);
    $aggrFilter
      ->addAggregation($aggr);
    $aggrFilter
      ->setFilter($facet_search_filter);
  }

  // Limit the number of returned entries.
  if ($facet_limit > 0 && method_exists($facet, 'setSize')) {
    $facet
      ->setSize($facet_limit);
  }
  return $facet;
}