public function Query::addCondition in Search API 8
Adds a new ($field $operator $value) condition.
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\Query\QueryInterface::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.
Return value
$this
Overrides ConditionSetInterface::addCondition
File
- src/
Query/ Query.php, line 454
Class
- Query
- Provides a standard implementation for a Search API query.
Namespace
Drupal\search_api\QueryCode
public function addCondition($field, $value, $operator = '=') {
$this->conditionGroup
->addCondition($field, $value, $operator);
return $this;
}