当结果具有相同分数时在 Azure 搜索中分页

Paging in Azure search when results have equal scores

我在我的电子商务网站上使用 Azure 搜索,现在我遇到了搜索页面分页的问题。当我重新加载搜索页面时,我可以获得不同的产品顺序。所以当我使用分页时,我可以在不同的页面上看到相同的产品,这很关键。

我开始研究出了什么问题,并且我在 Microsoft 文档上找到了此信息 https://docs.microsoft.com/en-us/rest/api/searchservice/add-scoring-profiles-to-a-search-index#what-is-default-scoring

Search score values can be repeated throughout a result set. For example, you might have 10 items with a score of 1.2, 20 items with a score of 1.0, and 20 items with a score of 0.5. When multiple hits have the same search score, the ordering of same scored items is not defined, and is not stable. Run the query again, and you might see items shift position. Given two items with an identical score, there is no guarantee which one appears first.

所以如果我没看错的话,我会遇到这个问题,因为产品有相同的分数。

如何解决这个问题?

你没看错!因为你得到的产品有相同的分数,所以不能保证哪个先出现。 为了在这个阶段避免它,您可以向 $orderby 参数添加一个具有唯一值的字段,这样您就可以保证相同的顺序。但是,这种方法没有考虑得分。我们目前正在研究这个问题的解决方案。一旦解决方案可用,我们将更新此答案(此时的 ETA 是数周,而不是数月)。

请注意,您现在可以使用 search.score() 函数按分数排序: 来自下面的 link: https://docs.microsoft.com/en-us/rest/api/searchservice/odata-expression-syntax-for-azure-search。 "You can specify multiple sort criteria. The order of expressions determines the final sort order. For example, to sort descending by score, followed by rating, the syntax would be $orderby=search.score() desc,rating desc."