PHP 클래스 Cake\ElasticSearch\Query

상속: implements IteratorAggregat\IteratorAggregate, use trait Cake\Datasource\QueryTrait
파일 보기 프로젝트 열기: cakephp/elastic-search 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_dirty boolean Internal state to track whether or not the query has been modified.
$_elasticQuery
$_parts array The various query builder parts that will be transferred to the elastica query.
$_searchOptions array Additional options for Elastica\Type::search()

공개 메소드들

메소드 설명
__construct ( Type $repository ) Query constructor
aggregate ( array | AbstractAggregation $aggregation ) Add an aggregation to the elastic query object
applyOptions ( array $options ) Populates or adds parts to current query clauses using an array.
clause ( string $name ) : mixed Returns any data that was stored in the specified clause. This is useful for modifying any internal part of the query and it is used during compiling to transform the query accordingly before it is executed. The valid clauses that can be retrieved are: fields, preFilter, postFilter, query, order, limit and offset.
compileQuery ( ) : string Compile the Elasticsearch query.
find ( $type = 'all', $options = [] ) : Query {@inheritDoc}
highlight ( array $highlight ) Set the highlight options for the query.
limit ( integer $limit ) Sets the maximum number of results to return for this query.
offset ( integer $num ) Sets the number of records that should be skipped from the original result set This is commonly used for paginating large results. Accepts an integer.
order ( string | array $order, boolean $overwrite = false ) Sets the sorting options for the result set.
page ( integer $num, integer $limit = null ) Set the page of results you want.
postFilter ( array | callable | Elastica\Filter\AbstractFilter $conditions, boolean $overwrite = false ) Sets the filter to use in the post_filter object. Filters added using this method will be stacked on a bool filter.
query ( array $matcher ) Method to set the query
searchOptions ( array $options = null ) Set or get the search options
select ( array $fields, boolean $overwrite = false ) Adds fields to be selected from _source.
where ( array | callable | Elastica\Filter\AbstractFilter $conditions, boolean $overwrite = false ) Sets the filter to use in a FilteredQuery object. Filters added using this method will be stacked on a bool filter and applied to the filter part of a filtered query.

보호된 메소드들

메소드 설명
_buildFilter ( string $type, array | callable | Elastica\Filter\AbstractFilter $conditions, boolean $overwrite ) Auxiliary function used to parse conditions into filters and store them in a _parts variable.
_execute ( ) : ResultSet Executes the query.

메소드 상세

__construct() 공개 메소드

Query constructor
public __construct ( Type $repository )
$repository Type The type of document.

_buildFilter() 보호된 메소드

Auxiliary function used to parse conditions into filters and store them in a _parts variable.
protected _buildFilter ( string $type, array | callable | Elastica\Filter\AbstractFilter $conditions, boolean $overwrite )
$type string The name of the part in which the filters will be stored
$conditions array | callable | Elastica\Filter\AbstractFilter The list of conditions.
$overwrite boolean Whether or not to replace previous filters.

_execute() 보호된 메소드

Executes the query.
protected _execute ( ) : ResultSet
리턴 ResultSet The results of the query

aggregate() 공개 메소드

Add an aggregation to the elastic query object
public aggregate ( array | AbstractAggregation $aggregation )
$aggregation array | Elastica\Aggregation\AbstractAggregation One or multiple facets

applyOptions() 공개 메소드

This is handy for passing all query clauses at once. The option array accepts: - fields: Maps to the select method - conditions: Maps to the where method - order: Maps to the order method - limit: Maps to the limit method - offset: Maps to the offset method - page: Maps to the page method ### Example: $query->applyOptions([ 'fields' => ['id', 'name'], 'conditions' => [ 'created >=' => '2013-01-01' ], 'limit' => 10 ]); Is equivalent to: $query ->select(['id', 'name']) ->where(['created >=' => '2013-01-01']) ->limit(10)
public applyOptions ( array $options )
$options array list of query clauses to apply new parts to.

clause() 공개 메소드

The return value for each of those parts may vary. Some clauses use QueryExpression to internally store their state, some use arrays and others may use booleans or integers. This is summary of the return types for each clause. - fields: array, will return empty array when no fields are set - preFilter: The filter to use in a FilteredQuery object, returns null when not set - postFilter: The filter to use in the post_filter object, returns null when not set - query: Raw query (Elastica\Query\AbstractQuery), return null when not set - order: OrderByExpression, returns null when not set - limit: integer, null when not set - offset: integer, null when not set
public clause ( string $name ) : mixed
$name string name of the clause to be returned
리턴 mixed

compileQuery() 공개 메소드

Compile the Elasticsearch query.
public compileQuery ( ) : string
리턴 string The Elasticsearch query.

find() 공개 메소드

{@inheritDoc}
public find ( $type = 'all', $options = [] ) : Query
리턴 Query

highlight() 공개 메소드

Set the highlight options for the query.
public highlight ( array $highlight )
$highlight array The highlight options to use.

limit() 공개 메소드

This sets the size option for the Elastic Search query.
public limit ( integer $limit )
$limit integer The number of documents to return.

offset() 공개 메소드

Sets the number of records that should be skipped from the original result set This is commonly used for paginating large results. Accepts an integer.
public offset ( integer $num )
$num integer The number of records to be skipped

order() 공개 메소드

The accepted format for the $order parameter is: - [['name' => ['order'=> 'asc', ...]], ['price' => ['order'=> 'asc', ...]]] - ['name' => 'asc', 'price' => 'desc'] - 'field1' (defaults to order => 'desc')
public order ( string | array $order, boolean $overwrite = false )
$order string | array The sorting order to use.
$overwrite boolean Whether or not to replace previous sorting.

page() 공개 메소드

This method provides an easier to use interface to set the limit + offset in the record set you want as results. If empty the limit will default to the existing limit clause, and if that too is empty, then 25 will be used. Pages should start at 1.
public page ( integer $num, integer $limit = null )
$num integer The page number you want.
$limit integer The number of rows you want in the page. If null the current limit clause will be used.

postFilter() 공개 메소드

This method can be used in the same way the where() method is used. Please refer to its documentation for more details.
또한 보기: Cake\ElasticSearch\Query::where()
public postFilter ( array | callable | Elastica\Filter\AbstractFilter $conditions, boolean $overwrite = false )
$conditions array | callable | Elastica\Filter\AbstractFilter The list of conditions.
$overwrite boolean Whether or not to replace previous filters.

query() 공개 메소드

Method to set the query
public query ( array $matcher )
$matcher array Set the query parts

searchOptions() 공개 메소드

Set or get the search options
public searchOptions ( array $options = null )
$options array An array of additional search options

select() 공개 메소드

Calling this function multiple times will append more fields to the list of fields to be selected from _source. If true is passed in the second argument, any previous selections will be overwritten with the list passed in the first argument.
public select ( array $fields, boolean $overwrite = false )
$fields array The list of fields to select from _source.
$overwrite boolean Whether or not to replace previous selections.

where() 공개 메소드

There are several way in which you can use this method. The easiest one is by passing a simple array of conditions: {{{ Generates a {"term": {"name": "jose"}} json filter $query->where(['name' => 'jose']); }}} You can have as many conditions in the array as you'd like, Operators are also allowe in the field side of the array: {{{ $query->where(['name' => 'jose', 'age >' => 30, 'interests in' => ['php', 'cake']); }}} You can read about the available operators and how they translate to Elastic Search filters in the Cake\ElasticSearch\FilterBuilder::parse() method documentation. Additionally, it is possible to use a closure as first argument. The closure will receive a FilterBuilder instance, that you can use for creating arbitrary filter combinations: {{{ $query->where(function ($builder) { return $builder->and($builder->between('age', 10, 20), $builder->missing('name')); }); }}} Finally, you can pass any already built filters as first argument: {{{ $query->where(new \Elastica\Filter\Term('name.first', 'jose')); }}{
또한 보기: Cake\ElasticSearch\FilterBuilder
public where ( array | callable | Elastica\Filter\AbstractFilter $conditions, boolean $overwrite = false )
$conditions array | callable | Elastica\Filter\AbstractFilter The list of conditions.
$overwrite boolean Whether or not to replace previous filters.

프로퍼티 상세

$_dirty 보호되어 있는 프로퍼티

Internal state to track whether or not the query has been modified.
protected bool $_dirty
리턴 boolean

$_elasticQuery 보호되어 있는 프로퍼티

protected $_elasticQuery

$_parts 보호되어 있는 프로퍼티

The various query builder parts that will be transferred to the elastica query.
protected array $_parts
리턴 array

$_searchOptions 보호되어 있는 프로퍼티

Additional options for Elastica\Type::search()
protected array $_searchOptions
리턴 array