{@inheritdoc}

@param \Cake\ORM\Query $query Query.
@param array $options Options.
@return \Cake\ORM\Query
435642
public function findKv(Query $query, array $options)
    {
        return $query
            ->find('list', [
                'keyField' => 'path',
                'valueField' => 'value',
                'groupField' => 'namespace',
            ])
            ->formatResults(function ($results) {
                $resultSet = $results->toArray();
                if (isset($resultSet[''])) {
                    $resultSet += $resultSet[''];
                    unset($resultSet['']);
                }

                return $resultSet;
            });
    }
1368512
public function update($query, array $options = []) {
		$params = compact('query', 'options');

		return Filters::run($this, __FUNCTION__, $params, function($params) {
			$query = $params['query'];
			$exportedQuery = $query->export($this);

			if ($exportedQuery['fields'] === null) {
				return true;
			}

			$sql = $this->renderCommand('update', $exportedQuery, $query);
			$result = (boolean) $this->_execute($sql);

			if ($result && is_object($query) && $query->entity()) {
				$query->entity()->sync();
			}
			return $result;
		});
	}
242221
public function findValidToken(Query $query, array $options)
    {
        $options += [
            'token' => null,
            'expires >' => new DateTimeImmutable(),
            'status' => false
        ];

        return $query->where($options);
    }
139970
public function findForIndex(Query $query, array $options)
    {
        return $query->contain([
                $this->Categories->getAlias() => ['fields' => ['title', 'slug']],
                $this->Tags->getAlias() => function (Query $q) {
                    return $q->order(['tag' => 'ASC']);
                },
                $this->Users->getAlias() => ['fields' => ['id', 'first_name', 'last_name']],
            ])
            ->select(['id', 'title', 'preview', 'subtitle', 'slug', 'text', 'enable_comments', 'created'])
            ->order([sprintf('%s.created', $this->getAlias()) => 'DESC']);
    }
201589
public function query($sql, $key = null, $options = []) {
		return $this->object->query($sql, $key, $options);
	}
1368350
public static function format($query, array $options = [])
    {
        $lexer = new Lexer($query);
        $formatter = new self($options);

        return $formatter->formatList($lexer->list);
    }
512483
protected function _executeQuery(Query $query, array $options = [])
    {
        switch ($query->action()) {
            case Query::ACTION_CREATE:
                return $this->_executeCreateQuery($query, $options);
            case Query::ACTION_READ:
                return $this->_executeReadQuery($query, $options);
            case Query::ACTION_UPDATE:
                return $this->_executeUpdateQuery($query, $options);
            case Query::ACTION_DELETE:
                return $this->_executeDeleteQuery($query, $options);
        }

        return false;
    }
34343
protected function doFindAndRemove(array $query, array $options = array())
    {
        $document = parent::doFindAndRemove($query, $options);

        if (isset($document)) {
            // Remove the file data from the chunks collection
            $this->riakCollection->chunks->remove(array('files_id' => $document['_id']), $options);
        }

        return $document;
    }
893263
public function prepare($query, array $options = array())
    {
        // Replace prefix placeholder with prefix
        $query = str_replace("{prefix}", $this->prefix, $query);

        // Log last query and query count
        $this->lastQuery = $query;
        $this->queryCount++;

        // Statement time
        return new Statement($this->connection->prepare($query, $options), $this->connectionName);
    }
1193907
public function findSlugForFilterData(Query $query, array $options)
    {
        if (!isset($options['request']) || get_class($options['request']) !== ServerRequest::class) {
            user_error('The request query option must exist and must be of type Cake\Http\ServerRequest.');
        }

        if (!isset($options['filterData'])) {
            user_error('No filterData option provided.');
        }

        /** @var ServerRequest $request */
        $request = $options['request'];
        $filterData = $options['filterData'];

        return $query
            ->select($this->getAlias() . '.slug')
            ->where([
                $this->getAlias() . '.controller' => $request->getParam('controller'),
                $this->getAlias() . '.action' => $request->getParam('action'),
                $this->getAlias() . '.filter_data' => $this->_encodeFilterData($filterData)
            ])
            ->where($this->_pluginCondition($request));
    }
511464
public function findActive(Query $query, array $options)
    {
        return $query->innerJoinWith('Posts', function (Query $q) {
            return $q->find('active');
        })->distinct();
    }
1096030
private static function applyOptions(QueryBuilder $query, array $options)
    {
        if (isset($options['orderby'])) {
            $option = $options['orderby'];
            foreach ($option as $column => $order) {
                $query = $query->orderBy($column, $order);
            }
        }

        if (isset($options['for_update']) && $options['for_update'] === true) {
            $query->forUpdate();
        } elseif (isset($options['shared_lock']) && $options['shared_lock'] === true) {
            $query->sharedLock();
        }

        $limit  = $options['limit'] ?? null;
        $offset = $options['offset'] ?? 0;

        if ($limit !== null) {
            $query = $query->limit($limit, $offset);
        }

        return $query;
    }
563249
public function update($query, array $options = []) {
		$this->_checkConnection();

		$defaults = [
			'upsert' => false,
			'multiple' => true,
			'w' => $this->_config['w'],
			'wTimeoutMS' => $this->_config['wTimeoutMS'],
			'fsync' => false
		];
		$options += $defaults;

		$params = compact('query', 'options');

		return Filters::run($this, __FUNCTION__, $params, function($params) {
			$exporter = $this->_classes['exporter'];
			$prefix = $this->_config['gridPrefix'];

			$options = $params['options'];
			$query  = $params['query'];
			$args   = $query->export($this, ['keys' => ['conditions', 'source', 'data']]);
			$source = $args['source'];
			$data   = $args['data'];

			if ($query->entity()) {
				$data = $exporter::get('update', $data);
			}

			if ($source === "{$prefix}.files" && isset($data['update']['file'])) {
				$args['data']['_id'] = $this->_saveFile($data['update']);
			}
			$update = $query->entity() ? $exporter::toCommand($data) : $data;

			if (empty($update)) {
				return true;
			}
			if ($options['multiple'] && !preg_grep('/^\$/', array_keys($update))) {
				$update = ['$set' => $update];
			}
			$result = $this->connection->{$source}->update($args['conditions'], $update, $options);

			if ($this->_ok($result)) {
				$query->entity() ? $query->entity()->sync() : null;
				return true;
			}
			return false;
		});
	}
986154
public function findSitemapRecords(Query $query, array $options) {
		$query = $query
			->where($this->_config['conditions'])
			->cache("sitemap_{$query->repository()->alias()}", $this->_config['cacheConfigKey'])
			->order($this->_config['order'])
			->formatResults(function ($results) {
				return $this->mapResults($results);
			});

		if (!empty($this->_config['fields'])) {
			$query = $query->select($this->_config['fields']);
		}

		return $query;
	}
257896
protected function whereFamilyHash($query, EntryQueryOptions $options)
    {
        $query->when($options->familyHash, function ($query, $hash) {
            return $query->where('family_hash', $hash);
        });

        return $this;
    }
473412
protected function getPaginationData(Select $query, array $options)
    {
        // Get pagination options
        $page = (int) Arr::get($options, 'page');

        if ($page < 1) {
            $page = 1;
        }

        $resultsPerPage = Arr::get(
            $options,
            'resultsPerPage',
            $this->resultsPerPage
        );

        // Get total results
        $resultCount = $this->getQueryResultCount($query);
        $pageCount   = ceil($resultCount / $resultsPerPage);

        return new PaginationData([
            'page'             => $page,
            'page_count'       => $pageCount,
            'result_count'     => $resultCount,
            'results_per_page' => $resultsPerPage
        ]);
    }
962616
public function createSearch($query = '', $options = null, BuilderInterface $builder = null)
    {
        $search = new Search($this->getClient(), $builder);
        $search->addIndex($this);
        $search->setOptionsAndQuery($options, $query);

        return $search;
    }