serhiy-bzhezytskyy opened a new pull request, #16411: URL: https://github.com/apache/lucene/pull/16411
Closes #12370. ### Description Sorting on a string field that is **missing from the whole index** currently scans every document instead of early-terminating. When the sort field doesn't exist anywhere in the segment, every document ties on the "missing" value. With no tie-breaker, once the top-N priority queue is full, all remaining documents are non-competitive and can be skipped — but `TermOrdValComparator` didn't recognize this case, so it visited every doc. ### Fix `TermOrdValComparator` now mirrors the existing `singleSort` competitive-iterator recognition to the `minOrd` path, gated on `bottomValue == null` (i.e. the field is missing from the segment). This lets the comparator signal non-competitiveness and skip once the queue is full, exactly as it already does for present fields. Correctness is unchanged — results are identical; this is purely an optimization (so it's filed under Optimizations in CHANGES.txt). ### Tests Added a regression test to `TestSortOptimization` that asserts early termination happens (non-vacuous — it fails without the fix). `./gradlew :lucene:core:test --tests TestSortOptimization` → 29 tests, all green on current 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]
