@param mixed $keywords
@param \Doctrine\DBAL\Query\QueryBuilder $queryBuilder

@return string|null
426856
public function searchKeywords($keywords, $queryBuilder)
    {
        if ($this->attributeKey) {
            $result = $queryBuilder->expr()->like('ak_' . $this->attributeKey->getAttributeKeyHandle(), ':keywords');
        } else {
            $result = null;
        }

        return $result;
    }
129917
private function removeDuplicateJoins(QueryBuilder $queryBuilder)
    {
        if (empty($queryBuilder->getDQLParts()['join'])) {
            return $queryBuilder;
        }
        $joinArray = [];
        $joins = $queryBuilder->getDQLParts()['join']['a'];
        foreach ($joins as $join) {
            $joinArray[] = $join->getAlias();
        }
        $joinArray = array_unique($joinArray);
        foreach ($joins as $key => $join) {
            if (!array_key_exists($key, $joinArray)) {
                unset($joins[$key]);
            }
        }

        $queryBuilder->resetDQLPart('join');
        foreach ($joins as $join) {
            $queryBuilder->join($join->getJoin(), $join->getAlias());
        }

        return $queryBuilder;
    }
1226381
private function appendSearch(QueryBuilder $builder, array $criteria)
    {
        if (false === $this->isSearchQuery($criteria)) {
            return $this;
        }
        $builder->selectMeta('searchScore', 'textScore');
        $builder->sortMeta('searchScore', 'textScore');
        return $this;
    }
559534
public static function createQueryBuilder($queryBuilder)
    {
        if ($queryBuilder instanceof ORMBuilder) {
            return new ORMQueryBuilder($queryBuilder);
        }
        if ($queryBuilder instanceof DBALBuilder) {
            return new DBALQueryBuilder($queryBuilder);
        }

        throw new QueryBuilderException(
            sprintf('Invalid parameter "queryBuilder". Use %s or %s', ORMBuilder::class, DBALBuilder::class)
        );
    }
159675
protected function getPaginator4QueryBuilder($queryBuilder, $page = 1)
    {
        if (!$queryBuilder) {
            return null;
        }

        $adapter = new DoctrineAdapter(new ORMPaginator($queryBuilder));
        $paginator = new Paginator($adapter);
        $paginator->setDefaultItemCountPerPage($this->defaultItemCountPerPage);
        $paginator->setCurrentPageNumber($page);

        return $paginator;
    }
536062
protected function hasJoin(QueryBuilder $queryBuilder, $joinString)
    {
        /* @var \Doctrine\ORM\Query\Expr\Join $joinExpression */
        foreach ($queryBuilder->getDQLPart('join') as $joinsList) {
            foreach ($joinsList as $joinExpression) {
                if ($joinExpression->getJoin() == $joinString) {
                    return true;
                }
            }
        }

        return false;
    }
1184454
protected function getFixedQueryBuilder(QueryBuilder $queryBuilder)
    {
        $queryBuilderId = clone $queryBuilder;
        $rootAlias = current($queryBuilderId->getRootAliases());

        // step 1 : retrieve the targeted class
        $from = $queryBuilderId->getDQLPart('from');
        $class = $from[0]->getFrom();
        $metadata = $queryBuilderId->getEntityManager()->getMetadataFactory()->getMetadataFor($class);

        // step 2 : retrieve identifier columns
        $idNames = $metadata->getIdentifierFieldNames();

        // step 3 : retrieve the different subjects ids
        $selects = array();
        $idxSelect = '';
        foreach ($idNames as $idName) {
            $select = sprintf('%s.%s', $rootAlias, $idName);
            // Put the ID select on this array to use it on results QB
            $selects[$idName] = $select;
            // Use IDENTITY if id is a relation too. See: http://doctrine-orm.readthedocs.org/en/latest/reference/dql-doctrine-query-language.html
            // Should work only with doctrine/orm: ~2.2
            $idSelect = $select;
            if ($metadata->hasAssociation($idName)) {
                $idSelect = sprintf('IDENTITY(%s) as %s', $idSelect, $idName);
            }
            $idxSelect .= ($idxSelect !== '' ? ', ' : '') . $idSelect;
        }

        foreach ($queryBuilderId->getDqlParts()['orderBy'] as $sort) {
            $field = chop($sort->getParts()[0], 'ASC');
            $field = chop($field, 'DESC');
            $idxSelect .= ', (' . $field . ')';
        }

        $queryBuilderId->resetDQLPart('select');
        $queryBuilderId->add('select', 'DISTINCT ' . $idxSelect);

        // for SELECT DISTINCT, ORDER BY expressions must appear in idxSelect list
        /* Consider
            SELECT DISTINCT x FROM tab ORDER BY y;
        For any particular x-value in the table there might be many different y
        values.  Which one will you use to sort that x-value in the output?
        */
        // todo : check how doctrine behave, potential SQL injection here ...
        if ($this->getSortBy()) {
            $sortBy = $this->getSortBy();
            if (strpos($sortBy, '.') === false) { // add the current alias
                $sortBy = $rootAlias . '.' . $sortBy;
            }
            $sortBy .= ' AS __order_by';
            $queryBuilderId->addSelect($sortBy);
        }

        // Use ILIKE instead of LIKE for Postgresql
        if ('pdo_pgsql' == $queryBuilderId->getEntityManager()->getConnection()->getDriver()->getName()) {
            $this->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Blast\DoctrinePgsqlBundle\DoctrineExtensions\BlastWalker');
        }

        $query = $queryBuilderId->getQuery();
        foreach ($this->_hints as $name => $value) {
            $query->setHint($name, $value);
        }

        $results = $query->execute(array(), Query::HYDRATE_ARRAY);
        $platform = $queryBuilderId->getEntityManager()->getConnection()->getDatabasePlatform();
        $idxMatrix = array();
        foreach ($results as $id) {
            foreach ($idNames as $idName) {
                // Convert ids to database value in case of custom type, if provided.
                $fieldType = $metadata->getTypeOfField($idName);
                $idxMatrix[$idName][] = $fieldType && Type::hasType($fieldType)
                    ? Type::getType($fieldType)->convertToDatabaseValue($id[$idName], $platform)
                    : $id[$idName];
            }
        }

        // step 4 : alter the query to match the targeted ids
        foreach ($idxMatrix as $idName => $idx) {
            if (count($idx) > 0) {
                $idxParamName = sprintf('%s_idx', $idName);
                $idxParamName = preg_replace('/[^\w]+/', '_', $idxParamName);
                $queryBuilder->andWhere(sprintf('%s IN (:%s)', $selects[$idName], $idxParamName));
                $queryBuilder->setParameter($idxParamName, $idx);
                $queryBuilder->setMaxResults(null);
                $queryBuilder->setFirstResult(null);
            }
        }

        return $queryBuilder;
    }
761992
public function getQuery($queryParams)
    {
        return array_key_exists($queryParams, $this->query) ? $this->query[$queryParams] : null;
    }
1195368
private static function determineFilterIsNullOrIsNotNull(array $filter, QueryBuilder $queryBuilder)
    {
        if (!\in_array($filter['operation'], ['IS NULL', 'IS NOT NULL'])) {
            return null;
        }

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

        return static::filterComparing($filter, $queryBuilder);
    }
929212
public function useBoostQueriesFromTypoScript(): QueryBuilder
    {
        $searchConfiguration = $this->typoScriptConfiguration->getSearchConfiguration();

        if (!empty($searchConfiguration['query.']['boostQuery'])) {
            return $this->useBoostQueries($searchConfiguration['query.']['boostQuery']);
        }

        if (!empty($searchConfiguration['query.']['boostQuery.'])) {
            $boostQueries = $searchConfiguration['query.']['boostQuery.'];
            return $this->useBoostQueries(array_values($boostQueries));
        }

        return $this;
    }
999283
public function getQueryBuilderPartsForCachingHash($queryBuilder)
    {
        return [
            $queryBuilder->getQuery()->getSQL(),
            array_map([$this, 'parameterToArray'], $queryBuilder->getParameters()->toArray()),
        ];
    }
1097055
public function getFilter(QueryBuilder $qb, $dqlAlias)
    {
        if (null !== $this->dqlAlias) {
            $dqlAlias = $this->dqlAlias;
        }

        $field = ArgumentToOperandConverter::toField($this->field);

        return (string) $qb->expr()->isNotNull($field->transform($qb, $dqlAlias));
    }
1125347
public function extendQueryBuilder(QueryBuilder $queryBuilder)
    {
        $queryBuilder
            ->setFirstResult($this->getFirstResult())
            ->setMaxResults($this->getLimit());

        return $this;
    }
1246865
protected function addSearch(QueryBuilder $queryBuilder)
    {
        if ($this->search !== true) {
            return;
        }

        $request = $this->request->getCurrentRequest();

        $columns = $request->get('columns', array());

        $searchFields = array_intersect_key(array_values($this->fields), $columns);

        $globalSearch = $request->get('search');

        $orExpr = $queryBuilder->expr()->orX();

        $filteringType = $this->getFilteringType();

        foreach ($searchFields as $i => $searchField) {

            $searchField = $this->getSearchField($searchField);

            // Global filtering
            if ((!empty($globalSearch) || $globalSearch['value'] == '0') && $columns[$i]['searchable'] === "true") {

                $qbParam = "sSearch_global_" . $i;

                if ($this->isStringDQLQuery($searchField)) {

                    $orExpr->add(
                            $queryBuilder->expr()->eq($searchField, ':' . $qbParam)
                    );
                    $queryBuilder->setParameter($qbParam, $globalSearch['value']);

                } else {

                    $orExpr->add($queryBuilder->expr()->like($searchField, ":" . $qbParam));
                    $queryBuilder->setParameter($qbParam, "%" . $globalSearch['value'] . "%");

                }
            }

            // Individual filtering
            $searchName = "sSearch_" . $i;

            if($columns[$i]['searchable'] === "true" && $columns[$i]['search']['value'] != "") {

                $queryBuilder->andWhere($queryBuilder->expr()->like($searchField, ":" . $searchName));

                if (array_key_exists($i, $filteringType)) {
                    switch ($filteringType[$i]) {
                        case 's':
                            $queryBuilder->setParameter($searchName, $columns[$i]['search']['value']);
                            break;
                        case 'f':
                            $queryBuilder->setParameter($searchName, sprintf("%%%s%%", $columns[$i]['search']['value']));
                            break;
                        case 'b':
                            $queryBuilder->setParameter($searchName, sprintf("%%%s", $columns[$i]['search']['value']));
                            break;
                        case 'e':
                            $queryBuilder->setParameter($searchName, sprintf("%s%%", $columns[$i]['search']['value']));
                            break;
                    }
                } else {
                    $queryBuilder->setParameter($searchName, sprintf("%%%s%%", $columns[$i]['search']['value']));
                }
            }
        }

        if ((!empty($globalSearch) || $globalSearch == '0') && $orExpr->count() > 0) {
            $queryBuilder->andWhere($orExpr);
        }
    }
454705
protected function _addSearch(\Doctrine\ORM\QueryBuilder $queryBuilder)
    {
        if ($this->search == TRUE)
        {
            $request       = $this->request;
            $search_fields = array_values($this->fields);
            foreach ($search_fields as $i => $search_field)
            {
                $search_param = $request->get("sSearch_{$i}");
                if ($search_param !== false && $search_param != '')
                {
                    $field        = explode(' ', trim($search_field));
                    $search_field = $field[0];

                    $queryBuilder->andWhere(" $search_field like :ssearch{$i} ");
                    $queryBuilder->setParameter("ssearch{$i}", '%' . $request->get("sSearch_{$i}") . '%');
                }
            }
        }
    }
826357
protected function getPaginator4QueryBuilder(QueryBuilder $queryBuilder, int $count, int $page = 1): ?Paginator
    {
        if (!$queryBuilder) {
            return null;
        }

        $paginator = new Paginator(
            new DoctrineAdapter\SimpleQueryDoctrine($count, $queryBuilder->getQuery())
        );
        $paginator->setDefaultItemCountPerPage(25);
        $paginator->setCurrentPageNumber($page);

        return $paginator;
    }