Paging in Azure search when results have equal scores
Asked Answered
N

2

3

I'm using Azure Search on my e-commerce site, and now i faced the problem with paging on my search page. When i reload the search page i can get different order of products. So when i'm using paging i can see same products on different pages, and this is critical.

I started researching what's going wrong, and i've found this info on Microsoft docs https://learn.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.

So if i got it correctly, i face this issue because products has same score.

How to fix this?

Niven answered 24/4, 2017 at 15:59 Comment(0)
M
3

You got it correctly! Because the products you are getting have the same score, there is no guarantee which one appears first. In order to avoid it in this stage, you can add to your $orderby parameter a field that has unique values, and that way you guarantee the same order. However, this approach doesn’t take scoring into account. We are currently working on a solution to this problem. We will update this answer once the solution is available (the ETA at this point is weeks, not months).

Mandrel answered 24/4, 2017 at 22:41 Comment(0)
M
3

Please note that you can now use search.score() function to order by score: From the link below: https://learn.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."

Mandrel answered 24/5, 2017 at 22:39 Comment(1)
Thanks for answer!Niven

© 2022 - 2024 — McMap. All rights reserved.