Process paging and full text search

@return \SelectQuery
It can be an extended query, so use this object.
429640
final protected function process(\SelectQueryInterface $select, Query $query)
    {
        $sortField = null;

        if ($query->hasSortField()) {
            $sortField = $query->getSortField();

            $select->orderBy($this->fields[$sortField]['column'], Query::SORT_DESC === $query->getSortOrder() ? 'desc' : 'asc');
        }

        // Add a predictible ordering column
        if ($sortField !== $this->idColumn) {
            $select->orderBy($this->idColumn, Query::SORT_DESC === $query->getSortOrder() ? 'desc' : 'asc');
        }

        if ($this->fulltextField) {
            if ($searchstring = $query->getSearchString()) {
                $select->condition($this->fulltextField, '%'.db_like($searchstring).'%', 'LIKE');
            }
        }

        $this->applyFilters($select, $query);

        return $select;
    }
404595
public function getQuery()
    {
        // Convert the query string to a query object if not already done.
        if (!$this->query instanceof Query) {
            $this->query = $this->query === null
                ? new Query()
                : Query::fromString($this->query);
        }

        return $this->query;
    }
462797
public function buildQueryBuilder()
    {
        $builder = new QueryBuilder();

        foreach ($this->parsers as $parser) {
            if ($parser->wasApplied()) {
                $parser->apply($builder);
            }
        }

        foreach ($this->sorts as $sort) {
            $builder->orderBy($sort[0], $sort[1]);
        }

        if (!empty($this->perPage)) {
            $builder->setPageSize($this->perPage);
        }

        if (!empty($this->page)) {
            $builder->setPage($this->page);
        }

        if (!empty($this->searchQuery)) {
            $builder->setSearchQuery($this->searchQuery);
        }

        return $builder;
    }
1098574
public function process()
    {

        // Initialize the query library we are using
        $class = new \ReflectionClass($this->queryLibrary);

        // Set the query pointer to the new instance of the library
        $this->query = $class->newInstance();

        unset($class);

        // Define the return
        $results = [];

        // @todo: Add break up into loop to split large arrays into smaller chunks

        // Do server challenge(s) first, if any
        $this->doChallenges();

        // Do packets for server(s) and get query responses
        $this->doQueries();

        // Now we should have some information to process for each server
        foreach ($this->servers as $server) {
            /* @var $server \GameQ\Server */

            // Parse the responses for this server
            $result = $this->doParseResponse($server);

            // Apply the filters
            $result = array_merge($result, $this->doApplyFilters($result, $server));

            // Sort the keys so they are alphabetical and nicer to look at
            ksort($result);

            // Add the result to the results array
            $results[$server->id()] = $result;
        }

        return $results;
    }
711944
protected function _process()
    {
        if ($this->__isProcessed === true) {
            return $this;
        }

        $limit = $this->getLimit();
        if (is_null($limit)) {
            $this->setPagesNumber(1);
            $this->setOffset(0);
        } else {
            $this->setPagesNumber(round($this->getItemsNumber() / $this->getLimit()));
        }

        $this->__isProcessed = true;
        return $this;
    }
909320
private function buildQuery()
    {
        $this->datatableQuery->setSelectFrom();
        $this->datatableQuery->setLeftJoins();
        $this->datatableQuery->setWhere();
        $this->datatableQuery->setWhereCallbacks();
        $this->datatableQuery->setOrderBy();
        $this->datatableQuery->setLimit();

        return $this;
    }
1258025
protected function getQueryResult()
    {
        if ($this->queryResult) {
            return $this->queryResult;
        }

        return $this->queryResult = $this->getSelector()
            ->getSelectBuilder()
            ->execute();
    }
520483
public function makeQuery()
    {
        $query = $this->query()->select($this->makeSelect($this->columns()));

        return $query;
    }
264393
private function buildQuery()
    {
        $select = $this->buildSelect();

        $from = $this->buildFrom();

        $within = $this->buildWithin();

        $wheres = $this->buildWheres();

        $query = sprintf('%s %s %s %s', $select, $from, $within, $wheres);

        return trim($query);
    }
645476
public function buildQuery()
    {
        $model = $this->model;
        $query = $model::query();

        // perform joins
        if (is_array($this->join)) {
            foreach ($this->join as $condition) {
                list($joinModel, $column, $foreignKey) = $condition;
                $query->join($joinModel, $column, $foreignKey);
            }
        }

        // sanitze and set the filter
        $filter = $this->parseFilterInput($this->filter);
        $query->where($filter);

        // performs a search using LIKE queries
        // WARNING use sparingly, these queries are expensive
        if (!empty($this->search) && is_string($this->search) && property_exists($model, 'searchableProperties')) {
            $w = [];
            $search = addslashes($this->search);
            foreach ($model::$searchableProperties as $name) {
                $w[] = "`$name` LIKE '%$search%'";
            }

            if (count($w) > 0) {
                $query->where('('.implode(' OR ', $w).')');
            }
        }

        // eager loading
        foreach ($this->expand as $k) {
            $property = $model::getProperty($k);
            if ($property && isset($property['relation'])) {
                if (isset($property['id_property'])) {
                    $query->with($property['id_property']);
                } else {
                    $query->with($k);
                }
            }
        }

        if (isset($this->sort)) {
            $query->sort($this->sort);
        }

        // calculate limit and offset
        $start = ($this->page - 1) * $this->perPage;
        $query->start($start)->limit($this->perPage);

        return $query;
    }
27702
public function getQuery()
    {

        $strings = $this->string;
        $query = $this->buildQuery($this->getPattern($this->getChieldPattern()), $strings);

        return $query;
    }
1031771
protected function _query()
    {
        if ($this->_q)
            return $this->_q;

        $db = $this->gateway;
        if ($this->persist) {
            $db = $db->withOptions([
                'typeMap' => $this->typeMap,
            ]);
        }

        $this->_q = $db->selectCollection($this->collection_name);
        return $this->_q;
    }
566543
private function getQuerySelectQuery(): QueryBuilder
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('DISTINCT q.*, qt.*')
            ->from('ngbm_collection_query', 'q')
            ->innerJoin(
                'q',
                'ngbm_collection_query_translation',
                'qt',
                $query->expr()->andX(
                    $query->expr()->eq('qt.query_id', 'q.id'),
                    $query->expr()->eq('qt.status', 'q.status')
                )
            );

        return $query;
    }
794241
public function queryHook()
    {
        return function ($next, $query, $bag) {
            $method = $bag->get('method');
            $args   = $bag->get('args');
            $column = $args->get('column');

            if ($this->hasMapping($column)) {
                return call_user_func_array([$this, 'mappedQuery'], [$query, $method, $args]);
            }

            if (in_array($method, ['select', 'addSelect'])) {
                call_user_func_array([$this, 'mappedSelect'], [$query, $args]);
            }

            return $next($query, $bag);
        };
    }
1278863
public function selectAll()
    {
        if (is_null($this->sth)) {
            throw new QueryFailedException();
        }

        return $this->sth->fetchAll(\PDO::FETCH_OBJ);
    }
591606
final protected function process(\SelectQuery $select, Query $query)
    {
        $sortOrder = Query::SORT_DESC === $query->getSortOrder() ? 'desc' : 'asc';
        if ($query->hasSortField()) {
            $select->orderBy($query->getSortField(), $sortOrder);
        }
        $select->orderBy($this->getPredictibleOrderColumn(), $sortOrder);

        if ($searchString = $query->getSearchString()) {
            $select->condition('n.title', '%' . db_like($searchString) . '%', 'LIKE');
        }

        // Also add a few joins,  that might be useful later
        if ($query->has('history_user_id')) {
            $select->leftJoin('history', 'h', "h.nid = n.nid AND h.uid = :history_uid", [':history_uid' => $query->get('history_user_id')]);
        } else {
            $select->leftJoin('history', 'h', "h.nid = n.nid AND 1 = 0");
        }

        // This is where it potentially gets ugly in term of performance
        if ($query->has('revision_user_id')) {
            $revSelect = $this
                ->database
                ->select('node_revision', 'r')
                ->condition('r.uid', $query->has('revision_user_id'))
                ->where("r.nid = n.nid")
                ->range(0, 1)
            ;
            $revSelect->addExpression('1');

            $select->exists($revSelect);
        }

        $this->applyFilters($select, $query);

        /** @var \MakinaCorpus\Drupal\Calista\Datasource\QueryExtender\DrupalPager $pager */
        $this->pager = $select->extend(DrupalPager::class);
        $this->pager->setDatasourceQuery($query);

        return $this->pager;
    }
235832
public function process($query)
    {
        $this->_query = $query;

        $data = $this->_query->from;
        $data = $this->applyWhere($data, $this->_query->where);
        $data = $this->applyOrderBy($data, $this->_query->orderBy);
        $data = $this->applyLimit($data, $this->_query->limit, $this->_query->offset);

        return $data;
    }