知道如何使用学说查询生成器在ORDER BY
中添加分数吗?以下查询引发Expected end of string, got '+'
错误。
$qb = $this->createQueryBuilder('i')
->select(
'partial i.{ '.$fields.' }',
'partial c.{ id, title, description }',
'partial c2.{ id }',
'partial ch.{ id, name, icon, description }',
'partial t.{ id, tagname }',
"MATCH($searchFields) AGAINST(:searchTerm BOOLEAN) as score1",
'MATCH(t.tagname) AGAINST(:searchTerm BOOLEAN) as score2'
)
->join('i.categories', 'c')
->leftJoin('c.parent', 'c2')
->leftJoin('i.tags', 't')
->join('i.status', 's')
->join('c.channel', 'ch')
->join('ch.company', 'co')
->where("(MATCH($searchFields) AGAINST(:searchTerm BOOLEAN) > 5 OR MATCH(t.tagname) AGAINST(:searchTerm BOOLEAN) > 5 )")
->setParameters([
'searchTerm' => $searchTerm.'*',
])
->orderBy('score1 + score2', 'DESC');
没
关系,我通过简单地将字段加在一起来解决它。嘟嘟。
$qb = $this->createQueryBuilder('i')
->select(
'partial i.{ '.$fields.' }',
'partial c.{ id, title, description }',
'partial c2.{ id }',
'partial ch.{ id, name, icon, description }',
'partial t.{ id, tagname }',
"(MATCH($searchFields) AGAINST(:searchTerm BOOLEAN) + MATCH(t.tagname) AGAINST(:searchTerm BOOLEAN)) as score"
)