public function SearchApiQuery::addCondition in Search API 8
Adds a new ($field $operator $value) condition filter.
Parameters
string $field: The ID of the field to filter on, for example "status". The special fields "search_api_datasource" (filter on datasource ID), "search_api_language" (filter on language code) and "search_api_id" (filter on item ID) can be used in addition to all indexed fields on the index. However, for filtering on language code, using \Drupal\search_api\Plugin\views\query\SearchApiQuery::setLanguages is the preferred method, unless a complex condition containing the language code is required.
mixed $value: The value the field should have (or be related to by the operator). If $operator is "IN" or "NOT IN", $value has to be an array of values. If $operator is "BETWEEN" or "NOT BETWEEN", it has to be an array with exactly two values: the lower bound in key 0 and the upper bound in key 1 (both inclusive). Otherwise, $value must be a scalar.
string $operator: The operator to use for checking the constraint. The following operators are always supported for primitive types: "=", "<>", "<", "<=", ">=", ">", "IN", "NOT IN", "BETWEEN", "NOT BETWEEN". They have the same semantics as the corresponding SQL operators. Other operators might be added by backend features. If $field is a fulltext field, $operator can only be "=" or "<>", which are in this case interpreted as "contains" or "doesn't contain", respectively. If $value is NULL, $operator also can only be "=" or "<>", meaning the field must have no or some value, respectively.
string|null $group: (optional) The Views query filter group to add this filter to.
Return value
$this
See also
\Drupal\search_api\Query\QueryInterface::addCondition()
File
- src/
Plugin/ views/ query/ SearchApiQuery.php, line 1040
Class
- SearchApiQuery
- Defines a Views query class for searching on Search API indexes.
Namespace
Drupal\search_api\Plugin\views\queryCode
public function addCondition($field, $value, $operator = '=', $group = NULL) {
if (!$this
->shouldAbort()) {
// Ensure all variants of 0 are actually 0. Thus '', 0 and NULL are all
// the default group.
if (empty($group)) {
$group = 0;
}
$condition = [
$field,
$value,
$operator,
];
$this->where[$group]['conditions'][] = $condition;
}
return $this;
}