Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Based on this article <a href="http://www.doctrine-project.org/blog/doctrine2-custom-dql-udfs.html" rel="nofollow">Extending DQL in Doctrine 2: User-Defined Functions</a>:</p> <p>config.yml:</p> <pre><code>doctrine: orm: dql: string_functions: MATCH: My\Bundle\DQL\MatchAgainstFunction </code></pre> <p>MatchAgainstFunction.php</p> <pre><code>&lt;?php namespace My\Bundle\DQL; use Doctrine\ORM\Query\AST\Functions\FunctionNode; use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; /** * MatchAgainstFunction ::= * "MATCH" "(" StateFieldPathExpression {"," StateFieldPathExpression}* ")" "AGAINST" "(" * StringPrimary ["BOOLEAN"] ["EXPAND"] ")" */ class MatchAgainstFunction extends FunctionNode { /** @var array list of \Doctrine\ORM\Query\AST\PathExpression */ protected $pathExp = null; /** @var string */ protected $against = null; /** @var boolean */ protected $booleanMode = false; /** @var boolean */ protected $queryExpansion = false; public function parse(Parser $parser) { // match $parser-&gt;match(Lexer::T_IDENTIFIER); $parser-&gt;match(Lexer::T_OPEN_PARENTHESIS); // first Path Expression is mandatory $this-&gt;pathExp = array(); $this-&gt;pathExp[] = $parser-&gt;StateFieldPathExpression(); // Subsequent Path Expressions are optional $lexer = $parser-&gt;getLexer(); while ($lexer-&gt;isNextToken(Lexer::T_COMMA)) { $parser-&gt;match(Lexer::T_COMMA); $this-&gt;pathExp[] = $parser-&gt;StateFieldPathExpression(); } $parser-&gt;match(Lexer::T_CLOSE_PARENTHESIS); // against if (strtolower($lexer-&gt;lookahead['value']) !== 'against') { $parser-&gt;syntaxError('against'); } $parser-&gt;match(Lexer::T_IDENTIFIER); $parser-&gt;match(Lexer::T_OPEN_PARENTHESIS); $this-&gt;against = $parser-&gt;StringPrimary(); if (strtolower($lexer-&gt;lookahead['value']) === 'boolean') { $parser-&gt;match(Lexer::T_IDENTIFIER); $this-&gt;booleanMode = true; } if (strtolower($lexer-&gt;lookahead['value']) === 'expand') { $parser-&gt;match(Lexer::T_IDENTIFIER); $this-&gt;queryExpansion = true; } $parser-&gt;match(Lexer::T_CLOSE_PARENTHESIS); } public function getSql(SqlWalker $walker) { $fields = array(); foreach ($this-&gt;pathExp as $pathExp) { $fields[] = $pathExp-&gt;dispatch($walker); } $against = $walker-&gt;walkStringPrimary($this-&gt;against) . ($this-&gt;booleanMode ? ' IN BOOLEAN MODE' : '') . ($this-&gt;queryExpansion ? ' WITH QUERY EXPANSION' : ''); return sprintf('MATCH (%s) AGAINST (%s)', implode(', ', $fields), $against); } } </code></pre> <p>In your repository:</p> <pre><code>class MyRepository extends EntityRepository { public function getUsingAgainstMatch() { $qb = $this-&gt;getEntityManager()-&gt;createQueryBuilder(); $qb -&gt;select('m') -&gt;from('MyBundle:MyEntity', 'm') -&gt;andWhere('MATCH (m.field) AGAINST (:field) &gt; 1') -&gt;setParameter('field', 'value') ; return $qb; } //... } </code></pre> <p>You can find on this <a href="http://github.com/beberlei/DoctrineExtensions" rel="nofollow">repository</a> a lot of Doctrine Extensions.</p> <p>Hope this helps</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload