PHP 클래스 yii\sphinx\Query

Query provides a set of methods to facilitate the specification of different clauses in a SELECT statement. These methods can be chained together. By calling Query::createCommand, we can get a Command instance which can be further used to perform/execute the Sphinx query. For example, php $query = new Query(); $query->select('id, group_id') ->from('idx_item') ->limit(10); build and execute the query $command = $query->createCommand(); $command->sql returns the actual SQL $rows = $command->queryAll(); Since Sphinx does not store the original indexed text, the snippets for the rows in query result should be build separately via another query. You can simplify this workflow using [[snippetCallback]]. Warning: even if you do not set any query limit, implicit LIMIT 0,20 is present by default!
부터: 2.0
저자: Paul Klimov ([email protected])
상속: extends yii\db\Query
파일 보기 프로젝트 열기: yiisoft/yii2-sphinx 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$facets facet search specifications. For example: php [ 'group_id', 'brand_id' => [ 'order' => ['COUNT(*)' => SORT_ASC], ], 'price' => [ 'select' => 'INTERVAL(price,200,400,600,800) AS price', 'order' => ['FACET()' => SORT_ASC], ], 'name_in_json' => [ 'select' => [new Expression('json_attr.name AS name_in_json')], ], ] You need to use Query::search method in order to fetch facet results. Note: if you specify custom select for the facet, ensure facet name has corresponding column inside it.
$groupLimit groups limit: to return (no more than) N top matches for each group. This option will take effect only if [[groupBy]] is set.
$match text, which should be searched in fulltext mode. This value will be composed into MATCH operator inside the WHERE clause. Note: this value will be processed by [[Connection::escapeMatchValue()]], if you need to compose complex match condition use [[Expression]], see Query::match for details.
$options per-query options in format: optionName => optionValue They will compose OPTION clause. This is a Sphinx specific extension that lets you control a number of per-query options.
$showMeta whether to automatically perform 'SHOW META' query against main one. You may set this value to be string or [[Expression]] instance, in this case its value will be used as 'LIKE' condition for 'SHOW META' statement. You need to use Query::search method in order to fetch 'meta' results.
$snippetCallback PHP callback, which should be used to fetch source data for the snippets. Such callback will receive array of query result rows as an argument and must return the array of snippet source strings in the order, which match one of incoming rows. For example: php $query = new Query(); $query->from('idx_item') ->match('pencil') ->snippetCallback(function ($rows) { $result = []; foreach ($rows as $row) { $result[] = file_get_contents('/path/to/index/files/' . $row['id'] . '.txt'); } return $result; }) ->all();
$snippetOptions query options for the call snippet.
$within WITHIN GROUP ORDER BY clause. This is a Sphinx specific extension that lets you control how the best row within a group will to be selected. The possible value matches the [[orderBy]] one.

공개 메소드들

메소드 설명
addFacets ( array $facets ) Adds additional FACET part of the query.
addOptions ( array $options ) Adds additional query options.
addWithin ( string | array $columns ) Adds additional WITHIN GROUP ORDER BY columns to the query.
create ( Query $from ) : Query Creates a new Query object and copies its property values from an existing one.
createCommand ( Connection $db = null ) : Command Creates a Sphinx command that can be used to execute this query.
facets ( array $facets ) Sets FACET part of the query.
getConnection ( ) : Connection
groupLimit ( integer $limit ) Sets groups limit: to return (no more than) N top matches for each group.
innerJoin ( $table, $on = '', $params = [] )
join ( $type, $table, $on = '', $params = [] )
leftJoin ( $table, $on = '', $params = [] )
match ( string | yii\db\Expression | MatchExpression $query ) Sets the fulltext query text. This text will be composed into MATCH operator inside the WHERE clause.
one ( $db = null )
options ( array $options ) Sets the query options.
populate ( $rows )
rightJoin ( $table, $on = '', $params = [] )
search ( Connection $db = null ) : array Executes the query and returns the complete search result including e.g. hits, facets.
setConnection ( Connection $connection )
showMeta ( boolean | string | yii\db\Expression $showMeta ) Sets whether to automatically perform 'SHOW META' for the search query.
snippetCallback ( callable $callback ) Sets the PHP callback, which should be used to retrieve the source data for the snippets building.
snippetOptions ( array $options ) Sets the call snippets query options.
within ( string | array $columns ) Sets the WITHIN GROUP ORDER BY part of the query.

보호된 메소드들

메소드 설명
callSnippets ( array $source ) : array Builds a snippets from provided source data.
callSnippetsInternal ( array $source, string $from ) : array Builds a snippets from provided source data by the given index.
defaultConnection ( ) : Connection
fillUpSnippets ( array $rows ) : array | ActiveRecord[] Fills the query result rows with the snippets built from source determined by [[snippetCallback]] result.
queryScalar ( $selectExpression, $db )

메소드 상세

addFacets() 공개 메소드

Adds additional FACET part of the query.
public addFacets ( array $facets )
$facets array facet specifications.

addOptions() 공개 메소드

Adds additional query options.
또한 보기: options()
public addOptions ( array $options )
$options array query options in format: optionName => optionValue

addWithin() 공개 메소드

Adds additional WITHIN GROUP ORDER BY columns to the query.
또한 보기: within()
public addWithin ( string | array $columns )
$columns string | array the columns (and the directions) to find best row within a group. Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array (e.g. `['id' => Query::SORT_ASC, 'name' => Query::SORT_DESC]`). The method will automatically quote the column names unless a column contains some parenthesis (which means the column contains a DB expression).

callSnippets() 보호된 메소드

Builds a snippets from provided source data.
protected callSnippets ( array $source ) : array
$source array the source data to extract a snippet from.
리턴 array snippets list.

callSnippetsInternal() 보호된 메소드

Builds a snippets from provided source data by the given index.
protected callSnippetsInternal ( array $source, string $from ) : array
$source array the source data to extract a snippet from.
$from string name of the source index.
리턴 array snippets list.

create() 공개 정적인 메소드

The properties being copies are the ones to be used by query builders.
public static create ( Query $from ) : Query
$from Query the source query object
리턴 Query the new Query object

createCommand() 공개 메소드

Creates a Sphinx command that can be used to execute this query.
public createCommand ( Connection $db = null ) : Command
$db Connection the Sphinx connection used to generate the SQL statement. If this parameter is not given, the `sphinx` application component will be used.
리턴 Command the created Sphinx command instance.

defaultConnection() 보호된 메소드

protected defaultConnection ( ) : Connection
리턴 Connection default connection value.

facets() 공개 메소드

Sets FACET part of the query.
public facets ( array $facets )
$facets array facet specifications.

fillUpSnippets() 보호된 메소드

Fills the query result rows with the snippets built from source determined by [[snippetCallback]] result.
protected fillUpSnippets ( array $rows ) : array | ActiveRecord[]
$rows array raw query result rows.
리턴 array | ActiveRecord[] query result rows with filled up snippets.

getConnection() 공개 메소드

public getConnection ( ) : Connection
리턴 Connection Sphinx connection instance

groupLimit() 공개 메소드

This option will take effect only if [[groupBy]] is set.
부터: 2.0.6
public groupLimit ( integer $limit )
$limit integer group limit.

innerJoin() 공개 메소드

public innerJoin ( $table, $on = '', $params = [] )

join() 공개 메소드

public join ( $type, $table, $on = '', $params = [] )

leftJoin() 공개 메소드

public leftJoin ( $table, $on = '', $params = [] )

match() 공개 메소드

Note: this value will be processed by [[Connection::escapeMatchValue()]], if you need to compose complex match condition use [[Expression]]: php $query = new Query(); $query->from('my_index') ->match(new Expression(':match', ['match' => '@(content) ' . Yii::$app->sphinx->escapeMatchValue($matchValue)])) ->all();
public match ( string | yii\db\Expression | MatchExpression $query )
$query string | yii\db\Expression | MatchExpression fulltext query text.

one() 공개 메소드

public one ( $db = null )

options() 공개 메소드

Sets the query options.
또한 보기: addOptions()
public options ( array $options )
$options array query options in format: optionName => optionValue

populate() 공개 메소드

public populate ( $rows )

queryScalar() 보호된 메소드

protected queryScalar ( $selectExpression, $db )

rightJoin() 공개 메소드

public rightJoin ( $table, $on = '', $params = [] )

setConnection() 공개 메소드

public setConnection ( Connection $connection )
$connection Connection Sphinx connection instance

showMeta() 공개 메소드

Sets whether to automatically perform 'SHOW META' for the search query.
또한 보기: showMeta
public showMeta ( boolean | string | yii\db\Expression $showMeta )
$showMeta boolean | string | yii\db\Expression whether to automatically perform 'SHOW META'

snippetCallback() 공개 메소드

Sets the PHP callback, which should be used to retrieve the source data for the snippets building.
또한 보기: snippetCallback
public snippetCallback ( callable $callback )
$callback callable PHP callback, which should be used to fetch source data for the snippets.

snippetOptions() 공개 메소드

Sets the call snippets query options.
또한 보기: snippetCallback
public snippetOptions ( array $options )
$options array call snippet options in format: option_name => option_value

within() 공개 메소드

Sets the WITHIN GROUP ORDER BY part of the query.
또한 보기: addWithin()
public within ( string | array $columns )
$columns string | array the columns (and the directions) to find best row within a group. Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array (e.g. `['id' => Query::SORT_ASC, 'name' => Query::SORT_DESC]`). The method will automatically quote the column names unless a column contains some parenthesis (which means the column contains a DB expression).

프로퍼티 상세

$facets 공개적으로 프로퍼티

facet search specifications. For example: php [ 'group_id', 'brand_id' => [ 'order' => ['COUNT(*)' => SORT_ASC], ], 'price' => [ 'select' => 'INTERVAL(price,200,400,600,800) AS price', 'order' => ['FACET()' => SORT_ASC], ], 'name_in_json' => [ 'select' => [new Expression('json_attr.name AS name_in_json')], ], ] You need to use Query::search method in order to fetch facet results. Note: if you specify custom select for the facet, ensure facet name has corresponding column inside it.
public $facets

$groupLimit 공개적으로 프로퍼티

groups limit: to return (no more than) N top matches for each group. This option will take effect only if [[groupBy]] is set.
부터: 2.0.6
public $groupLimit

$match 공개적으로 프로퍼티

text, which should be searched in fulltext mode. This value will be composed into MATCH operator inside the WHERE clause. Note: this value will be processed by [[Connection::escapeMatchValue()]], if you need to compose complex match condition use [[Expression]], see Query::match for details.
public $match

$options 공개적으로 프로퍼티

per-query options in format: optionName => optionValue They will compose OPTION clause. This is a Sphinx specific extension that lets you control a number of per-query options.
public $options

$showMeta 공개적으로 프로퍼티

whether to automatically perform 'SHOW META' query against main one. You may set this value to be string or [[Expression]] instance, in this case its value will be used as 'LIKE' condition for 'SHOW META' statement. You need to use Query::search method in order to fetch 'meta' results.
public $showMeta

$snippetCallback 공개적으로 프로퍼티

PHP callback, which should be used to fetch source data for the snippets. Such callback will receive array of query result rows as an argument and must return the array of snippet source strings in the order, which match one of incoming rows. For example: php $query = new Query(); $query->from('idx_item') ->match('pencil') ->snippetCallback(function ($rows) { $result = []; foreach ($rows as $row) { $result[] = file_get_contents('/path/to/index/files/' . $row['id'] . '.txt'); } return $result; }) ->all();
public $snippetCallback

$snippetOptions 공개적으로 프로퍼티

query options for the call snippet.
public $snippetOptions

$within 공개적으로 프로퍼티

WITHIN GROUP ORDER BY clause. This is a Sphinx specific extension that lets you control how the best row within a group will to be selected. The possible value matches the [[orderBy]] one.
public $within