protected function FieldsProcessorPluginBase::processConditions in Search API 8
Preprocesses the query conditions.
Parameters
\Drupal\search_api\Query\ConditionInterface[]|\Drupal\search_api\Query\ConditionGroupInterface[] $conditions: An array of conditions, as returned by \Drupal\search_api\Query\ConditionGroupInterface::getConditions(), passed by reference.
1 call to FieldsProcessorPluginBase::processConditions()
- FieldsProcessorPluginBase::preprocessSearchQuery in src/
Processor/ FieldsProcessorPluginBase.php - Preprocesses a search query.
File
- src/
Processor/ FieldsProcessorPluginBase.php, line 417
Class
- FieldsProcessorPluginBase
- Provides a base class for processors that work on individual fields.
Namespace
Drupal\search_api\ProcessorCode
protected function processConditions(array &$conditions) {
$fields = $this->index
->getFields();
foreach ($conditions as $key => &$condition) {
if ($condition instanceof ConditionInterface) {
$field = $condition
->getField();
if (isset($fields[$field]) && $this
->testField($field, $fields[$field])) {
// We want to allow processors also to easily remove complete
// conditions. However, we can't use empty() or the like, as that
// would sort out filters for 0 or NULL. So we specifically check only
// for the empty string, and we also make sure the condition value was
// actually changed by storing whether it was empty before.
$value = $condition
->getValue();
$empty_string = $value === '';
$this
->processConditionValue($value);
// Conditions with (NOT) BETWEEN operator deserve special attention,
// as it seems unlikely that it makes sense to completely remove them.
// Processors that remove values are normally indicating that this
// value can't be in the index – but that's irrelevant for (NOT)
// BETWEEN conditions, as any value between the two bounds could still
// be included. We therefore never remove a (NOT) BETWEEN condition
// and also ignore it when one of the two values got removed.
// Processors who need different behavior have to override this
// method.
$between_operator = in_array($condition
->getOperator(), [
'BETWEEN',
'NOT BETWEEN',
]);
if ($between_operator && (!is_array($value) || count($value) < 2)) {
continue;
}
if ($value === '' && !$empty_string) {
unset($conditions[$key]);
}
else {
$condition
->setValue($value);
}
}
}
elseif ($condition instanceof ConditionGroupInterface) {
$child_conditions =& $condition
->getConditions();
$this
->processConditions($child_conditions);
}
}
}