MongoDB+Doctrine: How to sort the query by text search score

前端 未结 1 1565
-上瘾入骨i
-上瘾入骨i 2021-01-16 15:36

I have a code like this that searches by the text index:

$expr = $queryBuilder->expr()->operator(\'$text\', [\'$search\' => $this->value]);
$resu         


        
相关标签:
1条回答
  • 2021-01-16 16:06

    I could not find relevant documentation, but I did find this issue on the project's Github repo. The issue has a milestone of 1.2.0 release, but it seems it has already been released in the 1.1.x branch. The issue has been closed via this commit.

    From the commit, it seems that all you need to sort your results by the textScore metadata info is one extra method call on the query builder:

    $result = $queryBuilder
        ->equals($expr)
        ->sortMeta('fieldToSearch', 'textScore') // <- this
        ->getQuery()
        ->execute();
    
    0 讨论(0)
提交回复
热议问题