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()]].
Datei anzeigen
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
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.
public addParams ( array $params ) |
$params |
array |
list of expression parameter values indexed by parameter placeholders.
For example, `[':name' => 'Dan', ':age' => 31]`. |
The new condition and the existing one will be joined using the 'AND' (' ') operator.
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. |
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.
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. |
The new condition and the existing one will be joined using the 'OR' ('|') operator.
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. |
Sets the parameters to be parsed into the query.
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_oe 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.
$params public_oe 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.