2016-02-20 141 views
0

在我的項目,我有以下DQL擴展DQL擴展不工作

namespace Freedom\Doctrine\ORM\AST\Functions; 

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->match(Lexer::T_IDENTIFIER); 
     $parser->match(Lexer::T_OPEN_PARENTHESIS); 

     // first Path Expression is mandatory 
     $this->pathExp = array(); 
     $this->pathExp[] = $parser->StateFieldPathExpression(); 

     // Subsequent Path Expressions are optional 
     $lexer = $parser->getLexer(); 
     while ($lexer->isNextToken(Lexer::T_COMMA)) { 
      $parser->match(Lexer::T_COMMA); 
      $this->pathExp[] = $parser->StateFieldPathExpression(); 
     } 

     $parser->match(Lexer::T_CLOSE_PARENTHESIS); 

     // against 
     if (strtolower($lexer->lookahead['value']) !== 'against') { 
      $parser->syntaxError('against'); 
     } 

     $parser->match(Lexer::T_IDENTIFIER); 
     $parser->match(Lexer::T_OPEN_PARENTHESIS); 
     $this->against = $parser->StringPrimary(); 

     if (strtolower($lexer->lookahead['value']) === 'boolean') { 
      $parser->match(Lexer::T_IDENTIFIER); 
      $this->booleanMode = true; 
     } 

     if (strtolower($lexer->lookahead['value']) === 'expand') { 
      $parser->match(Lexer::T_IDENTIFIER); 
      $this->queryExpansion = true; 
     } 

     $parser->match(Lexer::T_CLOSE_PARENTHESIS); 
    } 

    public function getSql(SqlWalker $walker) 
    { 
     $fields = array(); 
     foreach ($this->pathExp as $pathExp) { 
      $fields[] = $pathExp->dispatch($walker); 
     } 

     $against = $walker->walkStringPrimary($this->against) 
       . ($this->booleanMode ? ' IN BOOLEAN MODE' : '') 
       . ($this->queryExpansion ? ' WITH QUERY EXPANSION' : ''); 

     return sprintf('MATCH (%s) AGAINST (%s)', implode(', ', $fields), $against); 
    } 

} 

,並在我的DQL我有

$builder->andWhere('MATCH (t.title) AGAINST (:title)') 
     ->setParameter('title', $param); 

我收到錯誤

[語法錯誤]線0,col 204:Error:Expected =,<,< =,<>,>,> =,!=,got'ORDER'

我有一個orderBy後,在我的DQL和。

有誰知道爲什麼學說正在尋找一個比較運算符?

回答

0

我已經想通了。我改變了我的DQL到

$builder->andWhere('MATCH (t.title) AGAINST (:title BOOLEAN) > 0') 
     ->setParameter('title', $param); 

它似乎現在工作。