PHP Class Elastica\Query

Creates different types of queries
Inheritance: extends Param
Show file Open project: ruflin/elastica Class Usage Examples

Protected Properties

Property Type Description
$_suggest Suggest query or not.

Public Methods

Method Description
__construct ( array | Elastica\Query\AbstractQuery $query = null ) Creates a query object.
addAggregation ( AbstractAggregation $agg ) Adds an Aggregation to the query.
addHighlight ( mixed $highlight ) Adds a highlight argument.
addScriptField ( string $name, Elastica\Script\AbstractScript $script ) Adds a Script to the query.
addSort ( mixed $sort ) Adds a sort param to the query.
create ( mixed $query ) : self Transforms a string or an array to a query object.
getQuery ( ) : Elastica\Query\AbstractQuery Gets the query object.
setExplain ( boolean $explain = true ) Enables explain on the query.
setFieldDataFields ( array $fieldDataFields ) Sets the fields not stored to be returned by the search.
setFrom ( integer $from ) Sets the start from which the search results should be returned.
setHighlight ( array $highlightArgs ) Sets highlight arguments for the query.
setMinScore ( float $minScore ) Allows filtering of documents based on a minimum score.
setPostFilter ( Elastica\Query\AbstractQuery $filter ) Sets post_filter argument for the query. The filter is applied after the query has executed.
setQuery ( Elastica\Query\AbstractQuery $query ) Sets the query.
setRawQuery ( array $query ) Sets query as raw array. Will overwrite all already set arguments.
setRescore ( mixed $rescore ) Add a Rescore.
setScriptFields ( array | ScriptFields $scriptFields ) Set script fields.
setSize ( integer $size = 10 ) Sets maximum number of results for this query.
setSort ( array $sortArgs ) Sets sort arguments for the query Replaces existing values.
setSource ( array | boolean $params ) Sets the _source field to be returned with every hit.
setStoredFields ( array $fields ) 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.
setSuggest ( Suggest $suggest ) Add a suggest term.
setTrackScores ( boolean $trackScores = true ) Keep track of the scores when sorting results.
setVersion ( boolean $version = true ) Enables version on the query.
toArray ( ) : array Converts all query params to an array.

Method Details

__construct() public method

Creates a query object.
public __construct ( array | Elastica\Query\AbstractQuery $query = null )
$query array | Elastica\Query\AbstractQuery OPTIONAL Query object (default = null)

addAggregation() public method

Adds an Aggregation to the query.
public addAggregation ( AbstractAggregation $agg )
$agg Elastica\Aggregation\AbstractAggregation

addHighlight() public method

Adds a highlight argument.
public addHighlight ( mixed $highlight )
$highlight mixed Add highlight argument

addScriptField() public method

Adds a Script to the query.
public addScriptField ( string $name, Elastica\Script\AbstractScript $script )
$name string
$script Elastica\Script\AbstractScript Script object

addSort() public method

Adds a sort param to the query.
public addSort ( mixed $sort )
$sort mixed Sort parameter

create() public static method

If query is empty,
public static create ( mixed $query ) : self
$query mixed
return self

getQuery() public method

Gets the query object.
public getQuery ( ) : Elastica\Query\AbstractQuery
return Elastica\Query\AbstractQuery

setExplain() public method

Enables explain on the query.
public setExplain ( boolean $explain = true )
$explain boolean OPTIONAL Enabled or disable explain (default = true)

setFieldDataFields() public method

Sets the fields not stored to be returned by the search.
public setFieldDataFields ( array $fieldDataFields )
$fieldDataFields array Fields not stored to be returned

setFrom() public method

Sets the start from which the search results should be returned.
public setFrom ( integer $from )
$from integer

setHighlight() public method

Sets highlight arguments for the query.
public setHighlight ( array $highlightArgs )
$highlightArgs array Set all highlight arguments

setMinScore() public method

Allows filtering of documents based on a minimum score.
public setMinScore ( float $minScore )
$minScore float Minimum score to filter documents by

setPostFilter() public method

Sets post_filter argument for the query. The filter is applied after the query has executed.
public setPostFilter ( Elastica\Query\AbstractQuery $filter )
$filter Elastica\Query\AbstractQuery

setQuery() public method

Sets the query.
public setQuery ( Elastica\Query\AbstractQuery $query )
$query Elastica\Query\AbstractQuery Query object

setRawQuery() public method

Sets query as raw array. Will overwrite all already set arguments.
public setRawQuery ( array $query )
$query array Query array

setRescore() public method

Add a Rescore.
public setRescore ( mixed $rescore )
$rescore mixed suggestion object

setScriptFields() public method

Set script fields.
public setScriptFields ( array | ScriptFields $scriptFields )
$scriptFields array | Elastica\Script\ScriptFields Script fields

setSize() public method

Sets maximum number of results for this query.
public setSize ( integer $size = 10 )
$size integer OPTIONAL Maximal number of results for query (default = 10)

setSort() public method

Sets sort arguments for the query Replaces existing values.
public setSort ( array $sortArgs )
$sortArgs array Sorting arguments

setSource() public method

Sets the _source field to be returned with every hit.
public setSource ( array | boolean $params )
$params array | boolean Fields to be returned or false to disable source

setStoredFields() public method

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.
public setStoredFields ( array $fields )
$fields array Fields to be returned

setSuggest() public method

Add a suggest term.
public setSuggest ( Suggest $suggest )
$suggest Suggest suggestion object

setTrackScores() public method

Keep track of the scores when sorting results.
public setTrackScores ( boolean $trackScores = true )
$trackScores boolean

setVersion() public method

Enables version on the query.
public setVersion ( boolean $version = true )
$version boolean OPTIONAL Enabled or disable version (default = true)

toArray() public method

Converts all query params to an array.
public toArray ( ) : array
return array Query array

Property Details

$_suggest protected property

Suggest query or not.
protected $_suggest