Postgres全文搜索DQL用户定义的函数问题

时间:2013-02-11 18:24:21

标签: php postgresql symfony doctrine-orm full-text-search

/**
 * PGSearchFunction ::= "PG_SEARCH" "(" StateFieldPathExpression "," StringPrimary ")"
 */
class PGSearch extends FunctionNode
{
    public $searchColumn = null;
    public $search = null;

    public function parse(Parser $parser)
    {
        $parser->match(Lexer::T_IDENTIFIER);
        $parser->match(Lexer::T_OPEN_PARENTHESIS);
        $this->searchColumn = $parser->StateFieldPathExpression();
        $parser->match(Lexer::T_COMMA);
        $this->search = $parser->StringPrimary(); 
        $parser->match(Lexer::T_CLOSE_PARENTHESIS);
    }

    public function getSql(SqlWalker $sqlWalker)
    {
        return sprintf("%s @@ to_tsquery('english', %s)", $this->searchColumn->dispatch($sqlWalker), $this->search->dispatch($sqlWalker));

    }

}

[语法错误]第0行,第1列:错误:预期=,<,< =,<>,>,> =,!=,得到字符串结尾。关于如何防止教条看起来像标准SQL表达式的任何建议?使用doctrine 2.2 btw。

1 个答案:

答案 0 :(得分:1)

您应该能够$em->createQuery("SELECT i FROM MyBundle:Invoice i WHERE PG_SEARCH(i.search, 'virus') = true");