serhiy-bzhezytskyy commented on code in PR #16434:
URL: https://github.com/apache/lucene/pull/16434#discussion_r3683468898
##########
lucene/core/src/java/org/apache/lucene/search/TopFieldCollector.java:
##########
@@ -45,20 +45,18 @@ private abstract class TopFieldLeafCollector implements
LeafCollector {
final LeafFieldComparator comparator;
final int reverseMul;
+ // Whether the search sort is a prefix of this segment's index sort
(decided per segment).
+ final boolean searchSortPartOfIndexSort;
Scorable scorer;
boolean collectedAllCompetitiveHits = false;
TopFieldLeafCollector(FieldValueHitQueue<Entry> queue, Sort sort,
LeafReaderContext context)
throws IOException {
- // as all segments are sorted in the same way, enough to check only the
1st segment for
- // indexSort
- if (searchSortPartOfIndexSort == null) {
- final Sort indexSort = context.reader().getMetaData().sort();
- searchSortPartOfIndexSort = canEarlyTerminate(sort, indexSort);
- if (searchSortPartOfIndexSort) {
- firstComparator.disableSkipping();
- }
- }
+ // Whether the search sort is a prefix of the index sort is decided per
segment: a MultiReader
+ // may combine segments with different index sorts, so this cannot be
cached across leaves
+ // (GITHUB#14399).
+ final Sort indexSort = context.reader().getMetaData().sort();
Review Comment:
Measured it since: substituting the shortcut into
`canEarlyTerminateOnPrefix` returns a wrong result — an index sorted `(a, c)`
searched by `(a, b)` gives the wrong top hit, because documents with equal `a`
are ordered by `c` so their `b` order is arbitrary.
`testCanEarlyTerminateOnPrefix` already asserts false for that shape. So the
follow-up isn't needed here — the full prefix comparison is load-bearing.
--
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]