Check if visitor is applicable to current criterion.

@param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion

@return bool
493542
public function canVisit(Criterion $criterion)
    {
        return
            $criterion instanceof Criterion\CustomField &&
            (
                $criterion->operator === Operator::LT ||
                $criterion->operator === Operator::LTE ||
                $criterion->operator === Operator::GT ||
                $criterion->operator === Operator::GTE ||
                $criterion->operator === Operator::BETWEEN
            );
    }
833193
public function isQuery()
    {
        if (false === $this->hasFilter(self::FILTER_QUERY)) {
            return false;
        }
        $query = $this->getFilter(self::FILTER_QUERY);
        return isset($query[self::FILTER_QUERY_CRITERIA]);
    }
1229984
public function matching(Criteria $criteria)
    {
        $persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName);

        return new LazyCriteriaCollection($persister, $criteria);
    }
974175
public function isSatisfiedBy($item): bool
    {
        if ($this->copyLimit === -1) {
            return true;
        }

        if ($this->copyLimit === 0) {
            return false;
        }

        $query = new LocationQuery([
            'filter' => new Criterion\Subtree($item->pathString),
        ]);

        $searchResults = $this->searchService->findLocations($query);

        if ($this->copyLimit >= $searchResults->totalCount) {
            return true;
        }

        return false;
    }
1246482
public function scanLocations(array $criteria)
    {
        $uris = $this->locations->map(function ($location) use ($criteria) {
            /** @var Location $location */
            return $location->getURI($criteria);
        })->filter(function ($uri) {
            return false !== $uri;
        });
        
        // Fall back for absolute paths on current filesystem.
        if ($uris->isEmpty()) {
            foreach ($criteria as $criterion) {
                if (file_exists($criterion)) {
                    return $criterion;
                }
            }
        }

        return $uris->isEmpty() ? false : $uris->first();
    }
1367265
protected function getCondition(Criterion $criterion)
    {
        $values = (array)$criterion->value;
        $start = $values[0];
        $end = isset($values[1]) ? $values[1] : null;
        if (($criterion->operator === Operator::LT) || ($criterion->operator === Operator::LTE)) {
            $end = $start;
            $start = null;
        }

        $range = $this->getQueryRange($criterion->operator, $start, $end);

        return array(
            'query_string' => array(
                'query' => 'fields_doc.' . $criterion->target . ':' . $range,
            ),
        );
    }
378227
public function canVisit(Criterion $criterion)
    {
        return
            $criterion instanceof Criterion\ContentId &&
            (
                ($criterion->operator ?: Operator::IN) === Operator::IN ||
                $criterion->operator === Operator::EQ
            );
    }
1181997
public function applyFilter(Criteria $criteria, $filter)
    {
        if (is_string($filter) && is_string($this->property)) {
            $criteria->andWhere(
                $criteria->expr()->contains($this->property, $filter)
            );
        }

        if (is_array($filter) && isset($filter[$this->searchKey])) {
            $criteria->andWhere(
                $criteria->expr()->contains($this->property, $filter[$this->searchKey])
            );
        }

        return $criteria;
    }
344082
public function countSmartyFilterI18ns(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collSmartyFilterI18nsPartial && !$this->isNew();
        if (null === $this->collSmartyFilterI18ns || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collSmartyFilterI18ns) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getSmartyFilterI18ns());
            }

            $query = ChildSmartyFilterI18nQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterBySmartyFilter($this)
                ->count($con);
        }

        return count($this->collSmartyFilterI18ns);
    }
1343582
public function canVisit(Criterion $criterion)
    {
        return
            $criterion instanceof Criterion\ParentLocationId &&
            (
                ($criterion->operator ?: Operator::IN) === Operator::IN ||
                $criterion->operator === Operator::EQ
            );
    }
666239
public function exists(array $criteria): bool
    {
        $query = $this->prepareQuery($criteria);
        $query->setSize(0);
        $query->setParam('terminate_after', 1);

        return $this->collection->search($query)->count() > 0;
    }
1033669
private function isSearchQuery(array $criteria)
    {
        if (isset($criteria['$text'])) {
            return true;
        }
        foreach ($criteria as $key => $value) {
            if (is_array($value) && true === $this->isSearchQuery($value)) {
                return true;
            }
        }
        return false;
    }
275767
public function check(Criteria $criteria, Message $message)
    {
        foreach ($criteria as $criterium) {
            if ($criterium instanceof Criteria) {
                if (!$this->check($criterium, $message)) {
                    return false;
                }

                return true;
            } elseif (!$criterium instanceof Criterium) {
                throw new InvalidArgumentException('Criterium is neither of type Criterium nor Criteria. Type is '.gettype($criterium));
            }

            $type = $criterium->getType();
            $value = $criterium->getValue();

            if (!strlen($value)) {
                continue;
            }

            switch ($type) {
                case Criteria::CRITERIUM_SUBJECT_LIKE:
                    if (stristr($message->getSubject(), $value) === false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_SUBJECT_NOT_LIKE:
                    if (stristr($message->getSubject(), $value) !== false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_BODY_LIKE:
                    if (stristr($message->getBody(), $value) === false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_BODY_NOT_LIKE:
                    if (stristr($message->getBody(), $value) !== false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_PRIORITY_IS:
                    if ($message->getPriority() !== $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_PRIORITY_MIN:
                    if ($message->getPriority() < $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_PRIORITY_IN:
                    if (!in_array($message->getPriority(), $value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_TYPE_IS:
                    if ($message->getType() !== $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_TYPE_IN:
                    if (!in_array($message->getType(), $value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_CHANNEL_IS:
                    if ($message->getChannel() !== $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_CHANNEL_LIKE:
                    if (stristr($message->getChannel(), $value) === false) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_CHANNEL_IN:
                    if (!in_array($message->getChannel(), $value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_ROLE_IS:
                    if ($message->getRole() !== $value) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_ROLE_IN:
                    if (!in_array($message->getRole(), $value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_MAX_AGE:
                    if ($message->getCreatedAt()->format('U') < (time() - ($value * 24 * 60 * 60))) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_MIN_AGE:
                    if ($message->getCreatedAt()->format('U') > (time() - ($value * 24 * 60 * 60))) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_START_DATE:
                    if ($message->getCreatedAt()->format('U') < strtotime($value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_END_DATE:
                    if ($message->getCreatedAt()->format('U') > strtotime($value)) {
                        continue 2;
                    }
                    break;

                case Criteria::CRITERIUM_DATE_IS:
                    if ($message->getCreatedAt()->format('Y-m-d') !== date('Y-m-d', strtotime($value))) {
                        continue 2;
                    }
                    break;

                default:
                    continue 2;
                    break;
            }

            return true;
        }

        return false;
    }
1002152
protected function isTagNameMatching(array $criterion)
	{
		if ( !isset($criterion[self::CRITERION_TAG]) ) {
			return true;
		}

		return $this->isValueMatchingCriterionDefinition($this->getTagName(), $criterion[self::CRITERION_TAG]);
	}
1008714
public function applyFilter(Criteria $criteria, $filter)
    {
        if (!is_array($filter) || !is_array($this->filterable)) {
            return $criteria;
        }

        foreach ($this->filterable as $field) {
            if (array_key_exists($field, $filter)) {
                $this->processEqualFilter($criteria, $field, $filter[$field]);
                $this->processBetweenFilter($criteria, $field, $filter[$field]);
                $this->processOperatorFilter($criteria, $field, $filter[$field]);
            }
        }

        return $criteria;
    }
619823
public function search($criteria)
    {
        $this->loadModel('Content.Contents');

        try {
            $contents = $this->Contents->search($criteria);
            if ($contents->clause('limit')) {
                $this->paginate['limit'] = $contents->clause('limit');
            }

            // TO-DO: ask search-engine for operator presence
            if (strpos($criteria, 'language:') === false) {
                $contents = $contents->where([
                    'Contents.status >' => 0,
                    'Contents.language IN' => ['', null, I18n::locale()] // any or concrete
                ]);
            }

            $contents = $this->paginate($contents);
        } catch (\Exception $e) {
            $contents = new Collection([]);
        }

        $this->set(compact('contents', 'criteria'));
        $this->viewMode('search-result');
    }
388448
protected function compileCriterion(Criterion $criterion, array &$bindings): string
    {
        if ($criterion instanceof ValueCriterion) {
            $sql = sprintf(
                '%s %s %s',
                $this->compileIdentifier($criterion->column, $bindings),
                $criterion->rule,
                $this->compileValue($criterion->value, $bindings)
            );

            if ($criterion->rule === 'LIKE' && is_string($criterion->value)) {
                $sql .= ' ESCAPE ?';
                $this->mergeBindings($bindings, ['\\']);
            }

            return $sql;
        }

        if ($criterion instanceof ColumnsCriterion) {
            return sprintf(
                '%s %s %s',
                $this->compileIdentifier($criterion->column1, $bindings),
                $criterion->rule,
                $this->compileIdentifier($criterion->column2, $bindings)
            );
        }

        if ($criterion instanceof BetweenCriterion) {
            return sprintf(
                '(%s %sBETWEEN %s AND %s)',
                $this->compileIdentifier($criterion->column, $bindings),
                $criterion->not ? 'NOT ' : '',
                $this->compileValue($criterion->min, $bindings),
                $this->compileValue($criterion->max, $bindings)
            );
        }

        if ($criterion instanceof CriteriaCriterion) {
            $groupBindings = [];
            $groupSQL = $this->compileCriteria($criterion->criteria, $groupBindings);

            if ($groupSQL === '') {
                return '';
            } else {
                $this->mergeBindings($bindings, $groupBindings);

                return sprintf(
                    '%s(%s)',
                    $criterion->not ? 'NOT ' : '',
                    $groupSQL
                );
            }
        }

        if ($criterion instanceof ExistsCriterion) {
            return sprintf(
                '%sEXISTS %s',
                $criterion->not ? 'NOT ' : '',
                $this->compileSubQuery($criterion->subQuery, $bindings)
            );
        }

        if ($criterion instanceof InCriterion) {
            if (is_array($criterion->values)) {
                if (empty($criterion->values)) {
                    return $this->compileEmptyInCriterion($criterion, $bindings);
                }

                $subQuery = '';
                foreach ($criterion->values as $value) {
                    $subQuery .= ($subQuery ? ', ' : '(') . $this->compileValue($value, $bindings);
                }
                $subQuery .= ')';
            } else {
                $subQuery = $this->compileSubQuery($criterion->values, $bindings);
            }

            return sprintf(
                '%s %sIN %s',
                $this->compileIdentifier($criterion->column, $bindings),
                $criterion->not ? 'NOT ' : '',
                $subQuery
            );
        }

        if ($criterion instanceof NullCriterion) {
            return sprintf(
                '%s IS %sNULL',
                $this->compileIdentifier($criterion->column, $bindings),
                $criterion->isNull ? '' : 'NOT '
            );
        }

        if ($criterion instanceof RawCriterion) {
            return $this->compileSubQuery($criterion->raw, $bindings);
        }

        throw new InvalidQueryException('The given criterion '.get_class($criterion).' is unknown');
    }