mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-05-19 17:50:42 +00:00
* TopDocs: ensure stable sorting on equal score When selecting the top K documents by score, we need to ensure stable sorting. Until now, for documents with the same score, we were relying on the (arbitrary) order returned by the BinaryHeap used to implement the collectors. This patch fixes the problem by explicitly using the doc address when harvesting the `TopSegmentCollector` and when merging the results in `TopCollector::merge_fruits()`. This is important (for example) to implement pagination correctly using the TopDocs collector. If sorting isn't stable, documents that have the same score might be ranked in different positions depending on the specific K that was used, thus appearing in two different pages, or in none at all. Fixes gh-671 * TMP: alternative solution (see previous commit) If we add the constrait that D is also PartialOrd in ComparableDoc<T, D>, then we can move the comparison by doc address directly in the cmp implementation of ComparableDoc. * TMP rebase as first commit: add benchmarks for TopSegmentCollector * fixup! TMP: alternative solution (see previous commit) * TMP add changelog entry * TMP run cargo fmt