学说顺序按比赛与得分多个表



知道如何使用学说查询生成器在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"
            )

相关内容

  • 没有找到相关文章

最新更新