PHP Class yii\sphinx\MatchExpression

In conjunction with MatchBuilder this class provides ability to build sophisticated MATCH expressions. Instance of this class can be passed to [[Query::match()]]. For example: php use yii\sphinx\Query; use yii\sphinx\MatchExpression; $rows = (new Query()) ->match(new MatchExpression('@title :title', ['title' => 'Yii'])) ->all(); You may use MatchExpression::match, MatchExpression::andMatch and MatchExpression::orMatch to combine several conditions. For example: php use yii\sphinx\Query; use yii\sphinx\MatchExpression; $rows = (new Query()) ->match( produces '((@title "Yii") (@author "Paul")) | (@content "Sphinx")' : (new MatchExpression()) ->match(['title' => 'Yii']) ->andMatch(['author' => 'Paul']) ->orMatch(['content' => 'Sphinx']) ) ->all(); You may as well compose expressions with special operators like 'MAYBE', 'PROXIMITY' etc. For example: php use yii\sphinx\Query; use yii\sphinx\MatchExpression; $rows = (new Query()) ->match( produces '@title "Yii" MAYBE "Sphinx"' : (new MatchExpression())->match([ 'maybe', 'title', 'Yii', 'Sphinx', ]) ) ->all(); $rows = (new Query()) ->match( produces '@title "Yii"~10' : (new MatchExpression())->match([ 'proximity', 'title', 'Yii', 10, ]) ) ->all(); Note: parameters passed via [[params]] or generated from array conditions will be automatically escaped using [[Connection::escapeMatchValue()]].
See also: MatchBuilder
See also: http://sphinxsearch.com/docs/current.html#extended-syntax
Since: 2.0.6
Author: Paul Klimov ([email protected])
Inheritance: extends yii\base\Object
Show file Open project: yiisoft/yii2-sphinx

Public Properties

Property Type Description
$match MATCH expression. For example: ['title' => 'Yii', 'content' => 'Sphinx']. Note: being specified as a plain string this value will not be quoted or escaped, do not pass possible unsecured values (like the ones obtained from HTTP request) as a direct value.
$params list of match expression parameter values indexed by parameter placeholders. For example, [':name' => 'Dan', ':age' => 31]. These parameters will be automatically escaped using [[Connection::escapeMatchValue()]] and inserted into MATCH expression as a quoted strings.

Public Methods

Method Description
__construct ( string $match = null, array $params = [], array $config = [] ) Constructor.
addParams ( array $params ) Adds additional parameters to be parsed into the query.
andMatch ( string | array | yii\db\Expression $condition, array $params = [] ) Adds an additional MATCH condition to the existing one.
match ( string | array | yii\db\Expression $condition, array $params = [] ) Sets the MATCH expression.
orMatch ( string | array | yii\db\Expression $condition, array $params = [] ) Adds an additional MATCH condition to the existing one.
params ( array $params ) Sets the parameters to be parsed into the query.

Method Details

__construct() public method

Constructor.
public __construct ( string $match = null, array $params = [], array $config = [] )
$match string the MATCH expression
$params array expression parameters.
$config array name-value pairs that will be used to initialize the object properties

addParams() public method

Adds additional parameters to be parsed into the query.
See also: params()
public addParams ( array $params )
$params array list of expression parameter values indexed by parameter placeholders. For example, `[':name' => 'Dan', ':age' => 31]`.

andMatch() public method

The new condition and the existing one will be joined using the 'AND' (' ') operator.
See also: match()
See also: orMatch()
public andMatch ( string | array | yii\db\Expression $condition, array $params = [] )
$condition string | array | yii\db\Expression the new MATCH condition. Please refer to [[match()]] on how to specify this parameter.
$params array the parameters (name => value) to be parsed into the query.

match() public method

The method requires a $condition parameter, and optionally a $params parameter specifying the values to be parsed into the expression. The $condition parameter should be either a string (e.g. '@name "John"') or an array.
See also: andMatch()
See also: orMatch()
public match ( string | array | yii\db\Expression $condition, array $params = [] )
$condition string | array | yii\db\Expression the conditions that should be put in the MATCH expression.
$params array the parameters (name => value) to be parsed into the query.

orMatch() public method

The new condition and the existing one will be joined using the 'OR' ('|') operator.
See also: match()
See also: andMatch()
public orMatch ( string | array | yii\db\Expression $condition, array $params = [] )
$condition string | array | yii\db\Expression the new WHERE condition. Please refer to [[match()]] on how to specify this parameter.
$params array the parameters (name => value) to be parsed into the query.

params() public method

Sets the parameters to be parsed into the query.
See also: addParams()
public params ( array $params )
$params array list of expression parameter values indexed by parameter placeholders. For example, `[':name' => 'Dan', ':age' => 31]`.

Property Details

$match public property

MATCH expression. For example: ['title' => 'Yii', 'content' => 'Sphinx']. Note: being specified as a plain string this value will not be quoted or escaped, do not pass possible unsecured values (like the ones obtained from HTTP request) as a direct value.
See also: match()
public $match

$params public property

list of match expression parameter values indexed by parameter placeholders. For example, [':name' => 'Dan', ':age' => 31]. These parameters will be automatically escaped using [[Connection::escapeMatchValue()]] and inserted into MATCH expression as a quoted strings.
public $params