You are here

protected function SearchApiElasticsearchQuery::verifyFilterConfiguration in Search API Elasticsearch 7.2

Verify that a filter has the necessary array keys.

Parameters

$filter_array:

$ignored_field:

Return value

bool

Throws

Exception

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

File

includes/SearchApiElasticsearchQuery.inc, line 396

Class

SearchApiElasticsearchQuery
@file

Code

protected function verifyFilterConfiguration($filter_array, $ignored_field) {
  if (!array_key_exists('field_id', $filter_array) || !array_key_exists('field_value', $filter_array) || !isset($filter_array['filter_operator'])) {
    throw new Exception(t('Incorrect filter criteria is using for searching!'));
  }
  $field_id = $filter_array['field_id'];

  // If field should be ignored, we skip.
  if ($field_id === $ignored_field) {
    return TRUE;
  }
  if (!isset($this->index_fields[$field_id])) {
    throw new Exception(t(':field_id Undefined field ! Incorrect filter criteria is using for searching!', array(
      ':field_id' => $field_id,
    )));
  }

  // Check operator.
  if (empty($filter_array['filter_operator'])) {
    throw new Exception(t('Empty filter operator for :field_id field! Incorrect filter criteria is using for searching!', array(
      ':field_id' => $field_id,
    )));
  }
  return TRUE;
}