You are here

protected function SearchApiElasticsearchElastica::setFiltersConjunction in Search API Elasticsearch 7

Helper function thaht set filters conjunction.

1 call to SearchApiElasticsearchElastica::setFiltersConjunction()
SearchApiElasticsearchElastica::parseFilter in modules/elastica/includes/SearchApiElasticsearchElastica.inc
Recursively parse Search API filters.

File

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

Class

SearchApiElasticsearchElastica
Search API Elasticsearch Elastica service class.

Code

protected function setFiltersConjunction(&$filters, $conjunction) {
  if (count($filters) > 1) {
    if ($conjunction === 'OR') {
      $filter = new Elastica\Filter\BoolOr();
      $filter
        ->setFilters($filters);
      $filters = array(
        $filter,
      );
    }
    elseif ($conjunction === 'AND') {
      $filter = new Elastica\Filter\BoolAnd();
      $filter
        ->setFilters($filters);
      $filters = array(
        $filter,
      );
    }
    else {
      throw new Exception(t('Undefined conjunction :conjunction! Available values are :avail_conjunction! Incorrect filter criteria is using for searching!', array(
        ':conjunction!' => $conjunction,
        ':avail_conjunction' => $conjunction,
      )));
    }
  }
  return $filters;
}