You are here

protected function SearchBuilder::setFiltersConjunction in Elasticsearch Connector 8.7

Same name and namespace in other branches
  1. 8.2 src/ElasticSearch/Parameters/Builder/SearchBuilder.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Builder\SearchBuilder::setFiltersConjunction()
  2. 8.5 src/ElasticSearch/Parameters/Builder/SearchBuilder.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Builder\SearchBuilder::setFiltersConjunction()
  3. 8.6 src/ElasticSearch/Parameters/Builder/SearchBuilder.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Builder\SearchBuilder::setFiltersConjunction()

Helper function to set filters conjunction.

Parameters

array $filters: Array of filter parameters to be passed along to Elasticsearch.

string $conjunction: The conjunction used by the corresponding Search API condition group – either 'AND' or 'OR'.

Return value

array Returns the passed $filters array wrapped in an array keyed by 'should' or 'must', as appropriate, based on the given conjunction.

Throws

\Exception In case of an invalid $conjunction.

1 call to SearchBuilder::setFiltersConjunction()
SearchBuilder::getQueryFilters in src/ElasticSearch/Parameters/Builder/SearchBuilder.php
Recursively parse Search API condition group.

File

src/ElasticSearch/Parameters/Builder/SearchBuilder.php, line 481

Class

SearchBuilder
Class SearchBuilder.

Namespace

Drupal\elasticsearch_connector\ElasticSearch\Parameters\Builder

Code

protected function setFiltersConjunction(array &$filters, $conjunction) {
  if ($conjunction === 'OR') {
    $filters = [
      'should' => $filters,
    ];
  }
  elseif ($conjunction === 'AND') {
    $filters = [
      'must' => $filters,
    ];
  }
  else {
    throw new \Exception(t('Undefined conjunction :conjunction! Available values are :avail_conjunction! Incorrect filter criteria is using for searching!', [
      ':conjunction!' => $conjunction,
      ':avail_conjunction' => $conjunction,
    ]));
  }
  return [
    'bool' => $filters,
  ];
}