Search

The search-method itself. Needs a Query-object, adds filters and returns the Query-object.

@param \Cake\ORM\Query $query Query Object.
@param type $options Options.
@return \Cake\ORM\Query
435254
public function search(\Cake\ORM\Query $query, $options = [])
    {
        $_query = $this->Controller->request->query;
        $this->Controller->request->data = $_query;

        $params = $_query;
        $filters = $this->_normalize($this->config('filters'));

        foreach ($filters as $field => $options) {
            $hash = Hash::get($params, $options['column']);
            if (!empty($hash)) {
                $key = $this->_buildKey($field, $options);
                $value = $this->_buildValue($field, $options, $params);

                $query->where([$key => $value]);

                $this->_setValue($field, $options, $params);
            }
        }

        return $query;
    }
90438
public function search($query, $options = [])
    {
        $url = $this->instanceURLRepo->get();
        $url .= $this->resourceRepo->get('search');
        $url .= '?q=';
        $url .= urlencode($query);

        $searchResults = $this->request($url, $options);

        return $searchResults;
    }
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;
		});
	}
1307963
public function findDeleted($query, $options)
    {
        $query->where([
            $this->config('field') => $this->config('states.deleted'),
        ]);

        return $query;
    }
329238
public function search($query)
    {
        if ($this->hasSearch()) {

            $search = $this->search;

            // If it's a anonymous function
            if (!is_string($search) && is_callable($search)) {
                call_user_func($search, $this, $query);
            }
        }

        return $this;
    }
570892
public function save(Query $query, array $options = []) {
        $type = $query->getType();

        if ($type === Query::DELETE) {
            return $this->_processDelete($query, $options);

        } else if ($type === Query::INSERT) {
            return $this->_processCreate($query, $options);

        } else if ($type === Query::UPDATE) {
            return $this->_processUpdate($query, $options);
        }

        // No processing or events, just execute it directly
        return $this->getDriver()->executeQuery($query)->save();
    }
1269113
public function findConcept($query, $options)
    {
        $query->where([
            $this->config('field') => $this->config('states.concept'),
        ]);

        return $query;
    }
1345329
private function _runQuery($query, $options)
    {
        $this->_testQueryStarts($query, '[select|show]');
        $statement = $this->_executeQuery($query, $options);
        if (is_object($statement) && $statement instanceof \PDOStatement) {
            return $statement;
        }
        else {
            $this->_error(FQDBException::INTERNAL_ASSERTION_FAIL, FQDBException::FQDB_CODE);
        }
    }
151560
public function findSlugged(Query $query, array $options) {
		if (empty($options['slug'])) {
			throw new InvalidArgumentException("The 'slug' key is required for find('slugged')");
		}

		return $query->where([$this->_config['field'] => $options['slug']]);
	}
962899
public function query($query, $options = [])
    {
        $url = $this->instanceURLRepo->get();
        $url .= $this->resourceRepo->get('query');
        $url .= '?q=';
        $url .= urlencode($query);

        $queryResults = $this->request($url, $options);

        return $queryResults;
    }
979078
public function delete($query, array $options = []) {
		$params = compact('query', 'options');

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

			if (!empty($data['rev'])) {
				$conditions['rev'] = $data['rev'];
			}
			$result = $this->connection->delete(
				"{$this->_config['database']}/{$_path}",
				$conditions
			);
			$result = json_decode($result);
			$result = (isset($result->ok) && $result->ok === true);

			if ($query->entity()) {
				$query->entity()->sync(null, [], ['dematerialize' => true]);
			}
			return $result;
		});
	}
504493
final public function option($query)
    {
        try {
            $option = $this->options->find($query);
            $value  = $option->getValue();

        } catch (ObjectDoesNotExistException $e) {
            $value = false;
        }

        return $value;
    }
194099
public function findPending(QueryInterface $query, array $options) : QueryInterface
    {
        $query->where([
            'import_id' => $options['import']->id,
            'status' => static::STATUS_PENDING
        ]);

        return $query;
    }
490952
public function findWithTrashed(Query $query, array $options)
    {
        return $query->where(['OR' => [
            $query->newExpr()->isNotNull($this->getTrashField()),
            $query->newExpr()->isNull($this->getTrashField()),
        ]]);
    }
48885
protected function assignOptions($query, Options $options)
    {
        if ($options->hasLimit()) {
            /*
             * For mysql queries, to allow counting rows we must prepend
             * SQL_CALC_FOUND_ROWS to the select quantifiers
             */
            if ($options->getLimit() > 0) {
                $calc_found_rows = 'SQL_CALC_FOUND_ROWS';
                if (!preg_match("/$calc_found_rows/", $query)) {
                    $q = trim($query);
                    $query = preg_replace('/^select\b/i', "SELECT $calc_found_rows", $q);
                }
            }

            // mysql only, @todo make it rule everything (use traits)
            $replace_regexp = "LIMIT[\s]+[\d]+((\s*,\s*\d+)|(\s+OFFSET\s+\d+)){0,1}";

            $search_regexp = "$replace_regexp";
            if (!preg_match("/$search_regexp$/i", $query)) {
                // Limit is not already present
                $query .= ' LIMIT ' . $options->getLimit();
            } else {
                $query = preg_replace("/($replace_regexp)/i", 'LIMIT ' . $options->getLimit(), $query);
            }

            if ($options->hasOffset()) {
                $query .= ' OFFSET ' . $options->getOffset();
            }
        }

        return $query;
    }
611340
public function execute(Query $query, array $options = [])
    {
        $result = $this->_executeQuery($query, $options);

        if ($this->getDriver() === null) {
            throw new \UnexpectedValueException(__('No driver has been defined'));
        }

        // Write to the logger when one has been defined
        if ($this->getDriver()->getLogger()) {
            $this->_logQuery($query, $this->getDriver()->getLogger());
        }

        return $result;
    }
517297
public static function search($query, array $searchParameters = null)
    {
        $manager = static::getAlgoliaManager();

        return $manager->search(__CLASS__, $query, $searchParameters);
    }