Skip to content

Apache Lucene open-source search software

order was undefined in case of duplicate sort keys, this could lead to incorrect results (documents appearing twice in the result set, other documents missing) if there were more than 100 matches. PR:31241

Daniel Naber65ce0a021bf9
diff --git a/src/java/org/apache/lucene/search/FieldSortedHitQueue.java b/src/java/org/apache/lucene/search/FieldSortedHitQueue.java
index 9663c847075..dd5dd0bb8a0 100644
--- a/src/java/org/apache/lucene/search/FieldSortedHitQueue.java
+++ b/src/java/org/apache/lucene/search/FieldSortedHitQueue.java
@@ -95,6 +95,9 @@ extends PriorityQueue {
c = (fields[i].reverse) ? comparators[i].compare (docB, docA)
: comparators[i].compare (docA, docB);
}
+ // avoid random sort order that could lead to duplicates (bug #31241):
+ if (c == 0)
+ return docA.doc > docB.doc;
return c > 0;
}