You are here

protected function SearchApiQuery::sanitizeOperator in Search API 8

Adapts an operator for use in a Search API query.

This method maps Views' "!=" to the "<>" Search API uses.

Parameters

string $operator: The operator to adapt for use in the Search API.

Return value

string The sanitized operator.

2 calls to SearchApiQuery::sanitizeOperator()
SearchApiQuery::addWhere in src/Plugin/views/query/SearchApiQuery.php
Adds a simple condition to the query.
SearchApiQuery::transformDbCondition in src/Plugin/views/query/SearchApiQuery.php
Transforms a database condition to an equivalent search filter.

File

src/Plugin/views/query/SearchApiQuery.php, line 1216

Class

SearchApiQuery
Defines a Views query class for searching on Search API indexes.

Namespace

Drupal\search_api\Plugin\views\query

Code

protected function sanitizeOperator($operator) {
  if ($operator === '!=') {
    $operator = '<>';
  }
  elseif (in_array($operator, [
    'in',
    'not in',
    'between',
    'not between',
  ])) {
    $operator = strtoupper($operator);
  }
  elseif (in_array($operator, [
    'IS NULL',
    'IS NOT NULL',
  ])) {
    $operator = $operator == 'IS NULL' ? '=' : '<>';
  }
  return $operator;
}