protected function SearchApiElasticsearchElastica::getFilter in Search API Elasticsearch 7
Get filter by associative array.
1 call to SearchApiElasticsearchElastica::getFilter()
- SearchApiElasticsearchElastica::parseFilter in modules/
elastica/ includes/ SearchApiElasticsearchElastica.inc - Recursively parse Search API filters.
File
- modules/
elastica/ includes/ SearchApiElasticsearchElastica.inc, line 468 - Provides Elastica client for Search API Elasticsearch.
Class
- SearchApiElasticsearchElastica
- Search API Elasticsearch Elastica service class.
Code
protected function getFilter(array $filter_assoc) {
// Handles "empty", "not empty" operators.
if (!isset($filter_assoc['filter_value'])) {
switch ($filter_assoc['filter_operator']) {
case '<>':
$filter = new Elastica\Filter\Exists($filter_assoc['field_id']);
break;
case '=':
$filter = new Elastica\Filter\BoolNot(new Elastica\Filter\Exists($filter_assoc['field_id']));
break;
default:
throw new Exception(t('Value is empty for :field_id! Incorrect filter criteria is using for searching!', array(
':field_id' => $filter_assoc['field_id'],
)));
}
}
else {
switch ($filter_assoc['filter_operator']) {
case '=':
$filter = new Elastica\Filter\Term(array(
$filter_assoc['field_id'] => $filter_assoc['filter_value'],
));
break;
case '<>':
$filter = new Elastica\Filter\BoolNot(new Elastica\Filter\Term(array(
$filter_assoc['field_id'] => $filter_assoc['filter_value'],
)));
break;
case '>':
$filter = new Elastica\Filter\Range($filter_assoc['field_id'], array(
'from' => $filter_assoc['filter_value'],
'to' => NULL,
'include_lower' => FALSE,
'include_upper' => FALSE,
));
break;
case '>=':
$filter = new Elastica\Filter\Range($filter_assoc['field_id'], array(
'from' => $filter_assoc['filter_value'],
'to' => NULL,
'include_lower' => TRUE,
'include_upper' => FALSE,
));
break;
case '<':
$filter = new Elastica\Filter\Range($filter_assoc['field_id'], array(
'from' => NULL,
'to' => $filter_assoc['filter_value'],
'include_lower' => FALSE,
'include_upper' => FALSE,
));
break;
case '<=':
$filter = new Elastica\Filter\Range($filter_assoc['field_id'], array(
'from' => NULL,
'to' => $filter_assoc['filter_value'],
'include_lower' => FALSE,
'include_upper' => TRUE,
));
break;
default:
throw new Exception(t('Undefined operator :field_operator for :field_id field! Incorrect filter criteria is using for searching!', array(
':field_operator' => $filter_assoc['filter_operator'],
':field_id' => $filter_assoc['field_id'],
)));
}
}
return $filter;
}