如何将 Azure 搜索的 @search.score 作为自定义 $orderby 子句的一部分

How do you include Azure Search's @search.score as part of your custom $orderby clause

根据 this page,Azure 搜索结果的默认排序是按 Azure 自己的分数(降序)。但是,您可以提供 $orderby 子句,其定义为:

A list of comma-separated expressions to sort the results by. Each expression can be either a field name or a call to the geo.distance() function.

我想按 Azure 的@search.score desc、MyFieldOne、MyFieldTwo 排序。但是,我不知道如何引用 @search.score "field."

我试过以下方法:

$orderby=search.score+desc,MyFieldOne,MyFieldTwo
$orderby=@search.score+desc,MyFieldOne,MyFieldTwo
$orderby=%40search.score+desc,MyFieldOne,MyFieldTwo

这些都会导致 http 502 或 400s。

如何在我的请求中引用 @search.score 值?

已编辑

Azure 搜索现在支持使用新的 search.score() OData 函数按分数排序。例如,要按分数然后按名称排序,请执行以下操作:

$orderby=search.score() desc, name asc

API reference 已更新以包含新的 search.score() 函数。

原回答:

Azure 搜索目前不允许您在 orderby 子句中引用分数。请为此 UserVoice suggestion 投票,以帮助我们确定这项工作的优先级。

但是请注意,两个文档的分数很少会相同,因此在 $oderby=@search.score 之后使用决胜局很少会起作用,并且在大多数情况下,排序顺序等同于排序按排名,这是默认情况下发生的情况。