@param object               $qb
@param FilterInterface      $filter
@param QueryObjectInterface $queryObject

@throws \InvalidArgumentException
341118
public function applyFilter($qb, FilterInterface $filter, QueryObjectInterface $queryObject)
    {
        if ($queryObject instanceof FilterableQueryObjectInterface) {
            $filterMap = $queryObject->getFilterMap();

            /* @var $filterRule FilterRule */
            foreach ($filter as $filterRule) {
                // rule must be bound
                if (!$filterRule->isBound()) {
                    continue;
                }

                // rule must be present in the filter map
                if (!isset($filterMap[$filterRule->getName()])) {
                    throw new \InvalidArgumentException(\sprintf(
                        'Column "%s" is not present in the filter map',
                        $filterRule->getName()
                    ));
                }

                $this->filterRuleProcessor->process($qb, $filterRule, $filterMap[$filterRule->getName()]);
            }
        }
    }
143205
public function filter(array $constraints = [], string $shape = null, QueryBuilder $qb = null)
    {
        $qb = !is_null($qb) ? $qb : $this->createQueryBuilder('e');
        return $this->arrange($this->_by($qb, $constraints), $shape);
    }
1277103
public function buildQuery(QueryBuilder $qb, array $parameters)
    {
        $emConfig = $this->getEntityManager()->getConfiguration();
        $emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
        $emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
        $emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');

        if (isset($parameters['year'])) {
            $qb->andWhere('main_item.status = :article_status_scheduled AND YEAR(main_item.publishedAt) = :year')
                ->orWhere('main_item.status = :article_status_published AND main_item.publishedAt is null AND YEAR(main_item.createdAt) = :year')
                ->orWhere('main_item.status = :article_status_published AND YEAR(main_item.publishedAt) = :year')
                ->setParameter('year', $parameters['year'])
                ->setParameter('article_status_published', PageStatus::PUBLISHED)
                ->setParameter('article_status_scheduled', PageStatus::SCHEDULED);
        }
        if (isset($parameters['month'])) {
            $qb->andWhere('main_item.status = :article_status_scheduled AND MONTH(main_item.publishedAt) = :month')
                ->orWhere('main_item.status = :article_status_published AND main_item.publishedAt is null AND MONTH(main_item.createdAt) = :month')
                ->orWhere('main_item.status = :article_status_published AND MONTH(main_item.publishedAt) = :month')
                ->setParameter('month', $parameters['month'])
                ->setParameter('article_status_published', PageStatus::PUBLISHED)
                ->setParameter('article_status_scheduled', PageStatus::SCHEDULED);
        }
        if (isset($parameters['day'])) {
            $qb->andWhere('main_item.status = :article_status_scheduled AND DAY(main_item.publishedAt) = :day')
                ->orWhere('main_item.status = :article_status_published AND main_item.publishedAt is null AND DAY(main_item.createdAt) = :day')
                ->orWhere('main_item.status = :article_status_published AND DAY(main_item.publishedAt) = :day')
                ->setParameter('day', $parameters['day'])
                ->setParameter('article_status_published', PageStatus::PUBLISHED)
                ->setParameter('article_status_scheduled', PageStatus::SCHEDULED);
        }

        return $qb;
    }
678645
private function setWhere(QueryBuilder $qb)
    {
        $globalSearch = $this->requestParams['search']['value'];

        // global filtering
        if ('' != $globalSearch) {
            $orExpr = $qb->expr()->orX();

            foreach ($this->columns as $key => $column) {
                if (true === $this->isSearchColumn($column)) {
                    $searchField = $this->searchColumns[$key];
                    $orExpr->add($qb->expr()->like($searchField, '?'.$key));
                    $qb->setParameter($key, '%'.$globalSearch.'%');
                }
            }

            $qb->where($orExpr);
        }

        // individual filtering
        if (true === $this->individualFiltering) {
            $andExpr = $qb->expr()->andX();

            $i = 100;

            foreach ($this->columns as $key => $column) {
                if (true === $this->isSearchColumn($column)) {
                    $searchType = $column->getSearchType();
                    $searchField = $this->searchColumns[$key];
                    $searchValue = $this->requestParams['columns'][$key]['search']['value'];
                    $searchRange = $this->requestParams['columns'][$key]['name'] === 'daterange';
                    if ('' != $searchValue && 'null' != $searchValue) {
                        if ($searchRange) {
                            list($_dateStart, $_dateEnd) = explode(' - ', $searchValue);
                            $dateStart = new \DateTime($_dateStart);
                            $dateEnd = new \DateTime($_dateEnd);
                            $dateEnd->setTime(23, 59, 59);

                            $k = $i + 1;
                            $andExpr->add($qb->expr()->between($searchField, '?'.$i, '?'.$k));
                            $qb->setParameter($i, $dateStart->format('Y-m-d H:i:s'));
                            $qb->setParameter($k, $dateEnd->format('Y-m-d H:i:s'));
                            $i += 2;
                        } else {
                            $andExpr = $this->addCondition($andExpr, $qb, $searchType, $searchField, $searchValue, $i);
                            ++$i;
                        }
                    }
                }
            }

            if ($andExpr->count() > 0) {
                $qb->andWhere($andExpr);
            }
        }

        return $this;
    }
460249
public function setupQb(QueryBuilder $qb, $filters)
    {
        $this->qb = $qb;
        $this->c = 0;
        $this->bind = array();

        $filters = $this->_unify($filters);

        $this->_setupOrderyBy($qb, $filters['orderby']);

        $this->_setFilters($qb, $filters['filters']);

        $filters['offset'] and $qb->setFirstResult($filters['offset']);

        $filters['limit'] and $qb->setMaxResults($filters['limit']);

        return $qb;
    }
232727
protected function applyFilter(RestRequestContract $request, QueryBuilder $qb)
    {
        $entity = $this->base()->findById($request->getId());

        $relateCriteria = Criteria::create();
        $relateCriteria->andWhere($relateCriteria->expr()->eq($this->mappedBy(), $entity->getId()));

        $qb->innerJoin($qb->getRootAliases()[0].'.'.$this->mappedBy(), $this->mappedBy());
        $qb->addCriteria($relateCriteria);

        parent::applyFilter($request, $qb);
    }
1034298
public function search(SearchCondition\SearchConditionInterface $filter, SelectOrder\SelectOrderInterface $order = null)
	{
		if ( ! ($filter instanceof SearchCondition\ArraySearchCondition)) {
			throw new Exception\WrongInstance($filter, 'SearchCondition\ArraySearchCondition');
		}
		$filterClosure = $filter->getSearchClosure();

		$orderClosure = null;
		if ( ! \is_null($order)) {
			if ( ! ($order instanceof SelectOrder\ArraySelectOrder)) {
				throw new Exception\WrongInstance($order, 'SelectOrder\ArraySelectOrder');
			}
			$orderClosure = $order->getOrderClosure();
		}

		$result = $this->searchByClosure($filterClosure, $orderClosure);
		
		return $result;
	}
1077620
public function filterBy(array $filters, QueryBuilder $qb = null)
    {
        $filters = array_filter($filters, function ($filter) {
            return !empty($filter);
        });

        if (null === $qb) {
            $qb = $this->createFilterQueryBuilder();
        }

        foreach ($filters as $col => $value) {
            foreach ($this->getColumnParameters($col) as $colName => $colParam) {
                $compare = $this->getWhereOperator($col).'Where';

                if (in_array($col, $this->getLikeFilterColumns())) {
                    $qb
                        ->$compare(sprintf('%s LIKE :%s', $colName, $colParam))
                        ->setParameter($colParam, '%'.$value.'%')
                    ;
                }

                if (in_array($col, $this->getILikeFilterColumns())) {
                    $qb
                        ->$compare(sprintf('LOWER(%s) LIKE :%s', $colName, $colParam))
                        ->setParameter($colParam, '%'.strtolower($value).'%')
                    ;
                }

                if (in_array($col, $this->getEqualFilterColumns())) {
                    $qb
                        ->$compare(sprintf('%s = :%s', $colName, $colParam))
                        ->setParameter($colParam, $value)
                    ;
                }

                if (in_array($col, $this->getInFilterColumns())) {
                    $qb
                        ->$compare($qb->expr()->in(sprintf('%s', $colName), (array) $value))
                    ;
                }
            }
        }

        return $qb;
    }
232359
public function handleData(QueryHandlerInterface $queryHandler, FilterInterface $filter, $data): void
    {
        if (!$queryHandler instanceof EAVQueryHandlerInterface) {
            throw new BadQueryHandlerException($queryHandler, EAVQueryHandlerInterface::class);
        }
        if (!$queryHandler->isEAVFilter($filter)) {
            $this->fallbackFilterType->handleData($queryHandler, $filter, $data);

            return;
        }

        $eavQb = new EAVQueryBuilder($queryHandler->getQueryBuilder(), $queryHandler->getAlias());
        $eavQb->setContext($queryHandler->getQueryContext());
        $dqlHandlers = [];
        foreach ($filter->getAttributes() as $attributePath) {
            $attributeDqlHandlers = [];
            $attributeQb = null;
            if (!empty($data[DateRangeType::START_NAME])) {
                $attributeQb = $queryHandler->getEAVAttributeQueryBuilder($eavQb, $attributePath);
                $attributeDqlHandlers[] = $attributeQb->gte($data[DateRangeType::START_NAME]);
            }
            if (!empty($data[DateRangeType::END_NAME])) {
                if ($attributeQb) {
                    $attributeQb = clone $attributeQb;
                } else {
                    $attributeQb = $queryHandler->getEAVAttributeQueryBuilder($eavQb, $attributePath);
                }
                $attributeDqlHandlers[] = $attributeQb->lte($data[DateRangeType::END_NAME]);
            }
            if (0 < \count($attributeDqlHandlers)) {
                $dqlHandlers[] = $eavQb->getAnd($attributeDqlHandlers);
            }
        }

        if (0 < \count($dqlHandlers)) {
            $eavQb->apply($eavQb->getOr($dqlHandlers));
        }
    }
662409
private function filterByAvailability(QueryBuilder $qb)
    {
        $alias = $qb->getAllAliases()[0];
        $qb->andWhere($alias . '.reservationMovement IS NULL');

        return $qb;
    }
856572
protected function applyWhere(QueryBuilder $qb, array $where): void
    {
        $whereType = $this->getContext()->getDefinition()->getArgument('where')->getType();

        /** @var InputObjectDefinition $whereDefinition */
        $whereDefinition = $this->getContext()->getEndpoint()->getType($whereType);

        /** @var ObjectDefinition $node */
        $node = $this->getContext()->getEndpoint()->getType($this->getContext()->getDefinition()->getNode());

        foreach ($where as $filterName => $condition) {
            $filterDefinition = $whereDefinition->getField($filterName);

            //TODO: load filters from services
            /** @var FilterInterface $filter */
            $filter = (new \ReflectionClass($filterDefinition->getResolver()))->newInstanceWithoutConstructor();

            $fieldName = $filterDefinition->getMeta('filter_field');
            if ($fieldName && $node->hasField($fieldName)) {
                $relatedField = $node->getField($fieldName);
                $filterContext = new FilterContext($this->getContext()->getEndpoint(), $node, $relatedField);
            } else {
                $filterContext = new FilterContext($this->getContext()->getEndpoint(), $node);
            }

            $filter($filterContext, $qb, $condition);
        }
    }
114298
public function getFilter(QueryBuilder $qb, $dqlAlias)
    {
        if (null !== $this->dqlAlias) {
            $dqlAlias = $this->dqlAlias;
        }

        return sprintf('%s INSTANCE OF %s', $dqlAlias, $this->value);
    }
1109761
public function getFormOptions(QueryHandlerInterface $queryHandler, FilterInterface $filter): array
    {
        if (isset($filter->getFormOptions()['attribute'])) {
            return parent::getFormOptions($queryHandler, $filter);
        }

        if (!$queryHandler instanceof EAVQueryHandlerInterface) {
            throw new BadQueryHandlerException($queryHandler, EAVQueryHandlerInterface::class);
        }

        $eavAttributes = $queryHandler->getEAVAttributes($filter);
        if (\count($eavAttributes) > 1) {
            throw new \UnexpectedValueException(
                "Autocomplete filters does not support multiple attributes ({$filter->getCode()})"
            );
        }

        return array_merge(
            $this->getDefaultFormOptions($queryHandler, $filter),
            [
                'attribute' => reset($eavAttributes),
            ],
            $filter->getFormOptions()
        );
    }
1233825
public function setQueryBuilder($queryBuilder)
    {
        if (!is_object($queryBuilder)) {
            throw new InvalidQueryBuilderObject('Parameter must be an object of "\Doctrine\ORM\QueryBuilder" or "Doctrine\ODM\MongoDB\Query\Builder"');
        }

        if (!$queryBuilder instanceof QueryBuilder && !$queryBuilder instanceof Builder) {
            throw new InvalidQueryBuilderObject(sprintf('%s is not valid query builder object', get_class($queryBuilder)));
        }

        $this->queryBuilder = $queryBuilder;
    }
908896
protected function addExtendedAdvancedSearchWhereClause($qb, $filters)
    {
        $parseFilters = [];
        if (isset($filters->root[0])) {
            // Function is determined by the second clause type
            $type         = (isset($filters->root[1])) ? $filters->root[1]->type : $filters->root[0]->type;
            $parseFilters = &$filters->root;
        } elseif (isset($filters->children[0])) {
            $type         = (isset($filters->children[1])) ? $filters->children[1]->type : $filters->children[0]->type;
            $parseFilters = &$filters->children;
        } elseif (is_array($filters)) {
            $type         = (isset($filters[1])) ? $filters[1]->type : $filters[0]->type;
            $parseFilters = &$filters;
        }

        if (empty($type)) {
            $type = 'and';
        }

        $parameters  = [];
        $expressions = $qb->expr()->{"{$type}X"}();

        if ($parseFilters) {
            $this->parseExtendedSearchFilters($parseFilters, $qb, $expressions, $parameters);
        }

        return [$expressions, $parameters];
    }
714741
private static function determineFilterComparing(array $filter, QueryBuilder $queryBuilder)
    {
        if (!\in_array($filter['operation'], ['=', '>', '>=', '<', '<=', '<>'])) {
            return null;
        }

        return static::filterComparing($filter, $queryBuilder);
    }
447444
protected function search(QueryBuilder $qb, string $search): void
    {
        $query = $this->queryDefinition;
        $node = $this->objectDefinition;

        $em = $this->getManager();
        $metadata = $em->getClassMetadata($this->entity);

        $node->getFields();
        $columns = [];
        $searchFields = FieldOptionsHelper::normalize($query->getMeta('pagination')['search_fields'] ?? ['*']);
        foreach ($node->getFields() as $field) {
            if (!FieldOptionsHelper::isEnabled($searchFields, $field->getName())) {
                continue;
            }

            $config = FieldOptionsHelper::getConfig($searchFields, $field->getName(), null);
            $searchColumn = null;
            if ($metadata->hasField($field->getName())) {
                $searchColumn = $field->getName();
            }

            if ($metadata->hasField($field->getOriginName())) {
                $searchColumn = $field->getOriginName();
            }

            if ($searchColumn) {
                switch ($metadata->getFieldMapping($searchColumn)['type']) {
                    case Type::STRING:
                    case Type::TEXT:
                        $columns[$searchColumn] = $config ?? 'partial';
                        break;
                    case Type::INTEGER:
                    case Type::BIGINT:
                    case Type::FLOAT:
                    case Type::DECIMAL:
                    case Type::SMALLINT:
                        $columns[$searchColumn] = $config ?? 'exact';
                        break;
                }
            }
        }

        foreach ($searchFields as $field => $mode) {
            if (\is_int($field)) {
                $field = $mode;
                $mode = 'exact';
            }

            if ('*' === $field) {
                continue;
            }
            $columns[$field] = $mode;
        }


        if (\count($columns) > 0) {
            $joins = [];
            $orx = new Orx();
            foreach ($columns as $column => $mode) {
                $alias = $qb->getRootAliases()[0];
                if (strpos($column, '.') !== false) {
                    [$child, $column] = explode('.', $column);
                    $parentAlias = $alias;
                    $alias = 'searchJoin'.ucfirst($child);
                    if (!\in_array($alias, $joins, true)) {
                        $qb->leftJoin("{$parentAlias}.{$child}", $alias);
                        $joins[] = $alias;
                    }
                }

                if ('partial' === $mode) {
                    //search each word separate
                    $searchArray = explode(' ', $search);

                    $partialAnd = new Andx();
                    foreach ($searchArray as $q) {
                        $q = trim($q);
                        $partialAnd->add("$alias.$column LIKE '%$q%'");
                    }
                    $orx->add($partialAnd);
                } else {
                    $q = trim($search);
                    $orx->add("$alias.$column LIKE '$q'");
                }
            }

            $qb->andWhere($orx);
        }
    }