通过匹配得分多表的学说顺序

时间:2017-01-30 08:43:41

标签: php mysql doctrine-orm symfony

知道如何使用doctrine查询构建器在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');

1 个答案:

答案 0 :(得分:0)

没关系,我通过简单地将字段添加到一起来解决它。卫生署。

 $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"
            )