Properties

$_params

$_params : array

Params.

Type

array

$_rawParams

$_rawParams : array

Raw Params.

Type

array

$_suggest

$_suggest : integer

Suggest query or not.

Type

integer — Suggest

Methods

toArray()

toArray() : array

Converts all query params to an array.

Returns

array —

Query array

setParam()

setParam(string  $key, mixed  $value) : $this

Sets (overwrites) the value at the given key.

Parameters

string $key

Key to set

mixed $value

Key Value

Returns

$this

setParams()

setParams(array  $params) : $this

Sets (overwrites) all params of this object.

Parameters

array $params

Parameter list

Returns

$this

addParam()

addParam(string  $key, mixed  $value) : $this

Adds a param to the list.

This function can be used to add an array of params

Parameters

string $key

Param key

mixed $value

Value to set

Returns

$this

getParam()

getParam(string  $key) : mixed

Returns a specific param.

Parameters

string $key

Key to return

Throws

\Elastica\Exception\InvalidException

If requested key is not set

Returns

mixed —

Key value

hasParam()

hasParam(string  $key) : boolean

Test if a param is set.

Parameters

string $key

Key to test

Returns

boolean —

True if the param is set, false otherwise

getParams()

getParams() : array

Returns the params array.

Returns

array —

Params

__construct()

__construct(array|\Elastica\Query\AbstractQuery  $query = null) 

Creates a query object.

Parameters

array|\Elastica\Query\AbstractQuery $query

OPTIONAL Query object (default = null)

create()

create(mixed  $query) : self

Transforms the argument to a query object.

For example, an empty argument will return a \Elastica\Query with a \Elastica\Query\MatchAll.

Parameters

mixed $query

Throws

\Elastica\Exception\InvalidException

For an invalid argument

Returns

self

setRawQuery()

setRawQuery(array  $query) : $this

Sets query as raw array. Will overwrite all already set arguments.

Parameters

array $query

Query array

Returns

$this

setQuery()

setQuery(\Elastica\Query\AbstractQuery  $query) : $this

Sets the query.

Parameters

\Elastica\Query\AbstractQuery $query

Query object

Returns

$this

setFrom()

setFrom(integer  $from) : $this

Sets the start from which the search results should be returned.

Parameters

integer $from

Returns

$this

setSort()

setSort(array  $sortArgs) : $this

Sets sort arguments for the query Replaces existing values.

Parameters

array $sortArgs

Sorting arguments

Returns

$this

addSort()

addSort(mixed  $sort) : $this

Adds a sort param to the query.

Parameters

mixed $sort

Sort parameter

Returns

$this

setTrackScores()

setTrackScores(boolean  $trackScores = true) : $this

Keep track of the scores when sorting results.

Parameters

boolean $trackScores

Returns

$this

setHighlight()

setHighlight(array  $highlightArgs) : $this

Sets highlight arguments for the query.

Parameters

array $highlightArgs

Set all highlight arguments

Returns

$this

addHighlight()

addHighlight(mixed  $highlight) : $this

Adds a highlight argument.

Parameters

mixed $highlight

Add highlight argument

Returns

$this

setSize()

setSize(integer  $size = 10) : $this

Sets maximum number of results for this query.

Parameters

integer $size

OPTIONAL Maximal number of results for query (default = 10)

Returns

$this

setExplain()

setExplain(boolean  $explain = true) : $this

Enables explain on the query.

Parameters

boolean $explain

OPTIONAL Enabled or disable explain (default = true)

Returns

$this

setVersion()

setVersion(boolean  $version = true) : $this

Enables version on the query.

Parameters

boolean $version

OPTIONAL Enabled or disable version (default = true)

Returns

$this

setStoredFields()

setStoredFields(array  $fields) : $this

Sets the fields to be returned by the search NOTICE php will encode modified(or named keys) array into object format in json format request so the fields array must a sequence(list) type of array.

Parameters

array $fields

Fields to be returned

Returns

$this

setFieldDataFields()

setFieldDataFields(array  $fieldDataFields) : $this

Sets the fields not stored to be returned by the search.

Parameters

array $fieldDataFields

Fields not stored to be returned

Returns

$this

setScriptFields()

setScriptFields(array|\Elastica\Script\ScriptFields  $scriptFields) : $this

Set script fields.

Parameters

array|\Elastica\Script\ScriptFields $scriptFields

Script fields

Returns

$this

addScriptField()

addScriptField(string  $name, \Elastica\Script\AbstractScript  $script) : $this

Adds a Script to the query.

Parameters

string $name
\Elastica\Script\AbstractScript $script

Script object

Returns

$this

setMinScore()

setMinScore(float  $minScore) : $this

Allows filtering of documents based on a minimum score.

Parameters

float $minScore

Minimum score to filter documents by

Throws

\Elastica\Exception\InvalidException

Returns

$this

setSuggest()

setSuggest(\Elastica\Suggest  $suggest) : $this

Add a suggest term.

Parameters

\Elastica\Suggest $suggest

suggestion object

Returns

$this

setRescore()

setRescore(mixed  $rescore) : $this

Add a Rescore.

Parameters

mixed $rescore

suggestion object

Returns

$this

setSource()

setSource(array|boolean  $params) : $this

Sets the _source field to be returned with every hit.

Parameters

array|boolean $params

Fields to be returned or false to disable source

Returns

$this

setPostFilter()

setPostFilter(array|\Elastica\Query\AbstractQuery  $filter) : $this

Sets post_filter argument for the query. The filter is applied after the query has executed.

Parameters

array|\Elastica\Query\AbstractQuery $filter

Returns

$this

_convertArrayable()

_convertArrayable(array  $array) : array

Cast objects to arrays.

Parameters

array $array

Returns

array

_getBaseName()

_getBaseName() : string

Param's name Picks the last part of the class name and makes it snake_case You can override this method if you want to change the name.

Returns

string —

name

_setRawParam()

_setRawParam(string  $key, mixed  $value) : $this

Sets params not inside params array.

Parameters

string $key
mixed $value

Returns

$this