serhiy-bzhezytskyy commented on code in PR #16434:
URL: https://github.com/apache/lucene/pull/16434#discussion_r3683229245
##########
lucene/core/src/test/org/apache/lucene/search/TestTopFieldCollectorEarlyTermination.java:
##########
@@ -264,4 +268,88 @@ public void testCanEarlyTerminateOnPrefix() {
new SortField("c", SortField.Type.LONG),
new SortField("b", SortField.Type.STRING))));
}
+
+ /**
+ * GITHUB#14399: TopFieldCollector caches whether the search sort is a
prefix of the index sort
+ * after inspecting only the first leaf. That is safe for a single index
(IndexWriter enforces one
+ * index sort), but a MultiReader can span indexes with different index
sorts. Here the first
+ * index is sorted so the search sort IS a prefix (early termination is
eligible) while the second
+ * index is sorted the opposite way (it is NOT). The cached "yes" wrongly
early-terminates the
+ * second leaf and drops results that should rank first.
+ */
+ public void testMultiReaderWithDifferentIndexSorts() throws IOException {
+ final Sort ascSort = new Sort(new SortField("ndv", SortField.Type.LONG));
+
+ // Index A: sorted ndv ASC, many docs with a moderate value (50). Under an
ASC search sort this
+ // leaf is prefix-sorted, so the collector caches "search sort is part of
index sort" = true and
+ // calls disableSkipping().
+ Directory dirA = newDirectory();
+ IndexWriterConfig iwcA = newIndexWriterConfig().setIndexSort(ascSort);
+ iwcA.setMergeScheduler(new SerialMergeScheduler());
Review Comment:
No — removed. `forceMerge(1)` is synchronous so it makes no difference: 50
randomized iterations pass without it, and it still fails on unmodified main.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]