MatchBuilder¶
MatchBuilder helps compose advanced MATCH() expressions.
Use it directly, or pass a callback to SphinxQL::match().
Standalone Build¶
<?php
use Foolz\SphinxQL\MatchBuilder;
use Foolz\SphinxQL\SphinxQL;
$sq = new SphinxQL($conn);
$match = (new MatchBuilder($sq))
->field('content')
->match('directly')
->orMatch('lazy')
->compile()
->getCompiled();
// @content directly | lazy
Inline with Query Builder¶
$rows = (new SphinxQL($conn))
->select()
->from('rt')
->match(function ($m) {
$m->field('content')
->match('directly')
->orMatch('lazy');
})
->execute()
->getStored();
Real Compiled Examples from Tests¶
match('test case')->(test case)match('test')->orMatch('case')->test | casephrase('test case')->"test case"proximity('test case', 5)->"test case"~5quorum('this is a test case', 3)->"this is a test case"/3field('body', 50)->match('test')->@body[50] testignoreField('title', 'body')->match('test')->@!(title,body) testzone(['h3', 'h4'])->ZONE:(h3,h4)zonespan('th', 'test')->ZONESPAN:(th) test
Expressions and Escaping¶
Raw expression bypass:
use Foolz\SphinxQL\SphinxQL;
$expr = (new MatchBuilder($sq))
->match(SphinxQL::expr('test|case'))
->compile()
->getCompiled();
// test|case
Without Expression, special characters are escaped.