Doctrine orm 原则DQL扩展在Zend框架2中不起作用
我刚刚在ZF2应用程序中添加了一个DQL扩展,但它不起作用。 扩展应该允许对查询进行匹配 在我的module.config.php中Doctrine orm 原则DQL扩展在Zend框架2中不起作用,doctrine-orm,zend-framework2,dql,Doctrine Orm,Zend Framework2,Dql,我刚刚在ZF2应用程序中添加了一个DQL扩展,但它不起作用。 扩展应该允许对查询进行匹配 在我的module.config.php中 'doctrine' => array( 'driver' => array( 'Application_driver' => array( 'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'doctrine' => array(
'driver' => array(
'Application_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/Application/Entity')
),
'orm_default' => array(
'drivers' => array(
'Application\Entity' => 'Application_driver'
),
),
),
'configuration' => array(
'orm_default' => array(
'string_functions' => array(
'MatchAgainst' => 'Freedom\Doctrine\ORM\AST\Functions\MatchAgainstFunction',
),
'datetime_functions' => array(),
'numeric_functions' => array(),
'metadata_cache' => 'filesystem',
'query_cache' => 'filesystem',
'result_cache' => 'filesystem',
),
),
),
在我的DQL中,我有
$builder->andwhere('MATCH (`t.title`) AGAINST (:title)')
->setParameter('title', $param);
$builder->andWhere('MATCH (t.title) AGAINST (:title)')
->setParameter('title', $param);
扩展甚至没有被执行,我得到的只是一个错误
错误:预期为已知函数,获得“匹配”
有人知道我错过了什么吗
非常感谢
编辑
我已通过将行从
'matchback'=>'Freedom\doctor\ORM\AST\Functions\MatchAgainstFunction',
更改为'Match'=>'Freedom\doctor\ORM\AST\Functions\MatchAgainstFunction',
,使扩展正常工作
我现在遇到的问题是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);
$builder->andWhere('MATCH (t.title) AGAINST (:title)')
->setParameter('title', $param);
现在我得到了错误
[语法错误]第0行,第204列:错误:预期=,=,!=,有“命令”
有人知道为什么条令要寻找一个比较运算符吗?我通过将行从
'matchback'=>'Freedom\doctor\ORM\AST\Functions\MatchAgainstFunction',
更改为'Match'=>'Freedom\doctor\ORM\AST\Functions\MatchAgainstFunction',
在回答我的第二个问题时,我发现这是可行的
$builder->andWhere('MATCH (t.title) AGAINST (:title BOOLEAN) > 0')
->setParameter('title', $param);
我已通过将行从
'matchback'=>'Freedom\doctor\ORM\AST\Functions\MatchAgainstFunction',
更改为'Match'=>'Freedom\doctor\ORM\AST\Functions\MatchAgainstFunction',
在回答我的第二个问题时,我发现这是可行的
$builder->andWhere('MATCH (t.title) AGAINST (:title BOOLEAN) > 0')
->setParameter('title', $param);
谢谢你的回复。我遇到的问题是,在配置中注册的DQL函数没有运行。感谢您的回复。我遇到的问题是,在配置中注册的DQL函数没有运行。