You are here

protected function SearchApiElasticsearchQuery::getFilter in Search API Elasticsearch 7.2

Get Elasticsearch aggregation queries for Search API filters.

Parameters

$filter_array:

Return value

AbstractQuery || null

1 call to SearchApiElasticsearchQuery::getFilter()
SearchApiElasticsearchQuery::parseFilter in includes/SearchApiElasticsearchQuery.inc
Parse Search API filters.

File

includes/SearchApiElasticsearchQuery.inc, line 423

Class

SearchApiElasticsearchQuery
@file

Code

protected function getFilter($filter_array) {

  // Handle "empty", "not empty" operators.
  if (!isset($filter_array['field_value'])) {
    switch ($filter_array['filter_operator']) {
      case '<>':
        return new Exists($filter_array['field_id']);
      case '=':
        $query = new BoolQuery();
        $query
          ->addMustNot(new Exists($filter_array['field_id']));
        return $query;
    }
  }
  else {
    switch ($filter_array['field_value']) {
      case '>':
        $query = new RangeQuery($filter_array['field_id'], [
          'gt' => $filter_array['field_value'],
        ]);
        break;
      case '>=':
        $query = new RangeQuery($filter_array['field_id'], [
          'gte' => $filter_array['field_value'],
        ]);
        break;
      case '<':
        $query = new RangeQuery($filter_array['field_id'], [
          'lt' => $filter_array['field_value'],
        ]);
        break;
      case '<=':
        $query = new RangeQuery($filter_array['field_id'], [
          'lte' => $filter_array['field_value'],
        ]);
        break;
      default:
        $query = new Query\Term();
        $query
          ->setTerm($filter_array['field_id'], $filter_array['field_value']);
    }
    return $query;
  }
  return null;
}