diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index b82a4fc6d8e..9c2b2ec8c75 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -63,6 +63,10 @@ API Changes * LUCENE-10349: WordListLoader methods now return unmodifiable CharArraySets. (Uwe Schindler) +* LUCENE-10377: SortField.getComparator() has changed signature. The second parameter is now + a boolean indicating whether or not skipping should be enabled on the comparator. + (Alan Woodward) + New Features --------------------- @@ -187,6 +191,9 @@ Bug Fixes * LLUCENE-10353: Add random null injection to TestRandomChains. (Robert Muir, Uwe Schindler) +* LUCENE-10377: CheckIndex could incorrectly throw an error when checking index sorts + defined on older indexes. (Alan Woodward) + Other --------------------- diff --git a/lucene/core/src/java/org/apache/lucene/document/FeatureSortField.java b/lucene/core/src/java/org/apache/lucene/document/FeatureSortField.java index f06ead5b4d4..2a286802dcd 100644 --- a/lucene/core/src/java/org/apache/lucene/document/FeatureSortField.java +++ b/lucene/core/src/java/org/apache/lucene/document/FeatureSortField.java @@ -44,7 +44,7 @@ final class FeatureSortField extends SortField { } @Override - public FieldComparator getComparator(int numHits, int sortPos) { + public FieldComparator getComparator(int numHits, boolean enableSkipping) { return new FeatureComparator(numHits, getField(), featureName); } diff --git a/lucene/core/src/java/org/apache/lucene/document/LatLonPointSortField.java b/lucene/core/src/java/org/apache/lucene/document/LatLonPointSortField.java index 36f3935272f..768b27e4a11 100644 --- a/lucene/core/src/java/org/apache/lucene/document/LatLonPointSortField.java +++ b/lucene/core/src/java/org/apache/lucene/document/LatLonPointSortField.java @@ -38,7 +38,7 @@ final class LatLonPointSortField extends SortField { } @Override - public FieldComparator getComparator(int numHits, int sortPos) { + public FieldComparator getComparator(int numHits, boolean enableSkipping) { return new LatLonPointDistanceComparator(getField(), latitude, longitude, numHits); } diff --git a/lucene/core/src/java/org/apache/lucene/document/XYPointSortField.java b/lucene/core/src/java/org/apache/lucene/document/XYPointSortField.java index 2063a6c4ca1..f7f1632b491 100644 --- a/lucene/core/src/java/org/apache/lucene/document/XYPointSortField.java +++ b/lucene/core/src/java/org/apache/lucene/document/XYPointSortField.java @@ -35,7 +35,7 @@ final class XYPointSortField extends SortField { } @Override - public FieldComparator getComparator(int numHits, int sortPos) { + public FieldComparator getComparator(int numHits, boolean enableSkipping) { return new XYPointDistanceComparator(getField(), x, y, numHits); } diff --git a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java index f699937eb59..3dd5526a877 100644 --- a/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java +++ b/lucene/core/src/java/org/apache/lucene/index/CheckIndex.java @@ -1107,7 +1107,7 @@ public final class CheckIndex implements Closeable { for (int i = 0; i < fields.length; i++) { reverseMul[i] = fields[i].getReverse() ? -1 : 1; - comparators[i] = fields[i].getComparator(1, i).getLeafComparator(readerContext); + comparators[i] = fields[i].getComparator(1, false).getLeafComparator(readerContext); } int maxDoc = reader.maxDoc(); diff --git a/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java b/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java index 5d4f7687dd0..303dc516af8 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java +++ b/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java @@ -25,7 +25,6 @@ import org.apache.lucene.index.DocValues; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.PointValues; import org.apache.lucene.search.comparators.DoubleComparator; /** @@ -483,8 +482,8 @@ public abstract class DoubleValuesSource implements SegmentCacheable { @Override public FieldComparator newComparator( - String fieldname, int numHits, int sortPos, boolean reversed) { - return new DoubleComparator(numHits, fieldname, missingValue, reversed, sortPos) { + String fieldname, int numHits, boolean enableSkipping, boolean reversed) { + return new DoubleComparator(numHits, fieldname, missingValue, reversed, false) { @Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { DoubleValuesHolder holder = new DoubleValuesHolder(); @@ -499,11 +498,6 @@ public abstract class DoubleValuesSource implements SegmentCacheable { return asNumericDocValues(holder, Double::doubleToLongBits); } - @Override - protected PointValues getPointValues(LeafReaderContext context, String field) { - return null; - } - @Override public void setScorer(Scorable scorer) throws IOException { holder.values = producer.getValues(ctx, fromScorer(scorer)); diff --git a/lucene/core/src/java/org/apache/lucene/search/FieldComparatorSource.java b/lucene/core/src/java/org/apache/lucene/search/FieldComparatorSource.java index 15399268187..fd110b79ee9 100644 --- a/lucene/core/src/java/org/apache/lucene/search/FieldComparatorSource.java +++ b/lucene/core/src/java/org/apache/lucene/search/FieldComparatorSource.java @@ -30,5 +30,5 @@ public abstract class FieldComparatorSource { * @return FieldComparator. */ public abstract FieldComparator newComparator( - String fieldname, int numHits, int sortPos, boolean reversed); + String fieldname, int numHits, boolean enableSkipping, boolean reversed); } diff --git a/lucene/core/src/java/org/apache/lucene/search/FieldValueHitQueue.java b/lucene/core/src/java/org/apache/lucene/search/FieldValueHitQueue.java index 60596f33c48..5654313f7e1 100644 --- a/lucene/core/src/java/org/apache/lucene/search/FieldValueHitQueue.java +++ b/lucene/core/src/java/org/apache/lucene/search/FieldValueHitQueue.java @@ -134,7 +134,7 @@ public abstract class FieldValueHitQueue for (int i = 0; i < numComparators; ++i) { SortField field = fields[i]; reverseMul[i] = field.reverse ? -1 : 1; - comparators[i] = field.getComparator(size, i); + comparators[i] = field.getComparator(size, i == 0); } } diff --git a/lucene/core/src/java/org/apache/lucene/search/LongValuesSource.java b/lucene/core/src/java/org/apache/lucene/search/LongValuesSource.java index 4443b056824..2b2ed49795e 100644 --- a/lucene/core/src/java/org/apache/lucene/search/LongValuesSource.java +++ b/lucene/core/src/java/org/apache/lucene/search/LongValuesSource.java @@ -22,7 +22,6 @@ import java.util.Objects; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.PointValues; import org.apache.lucene.search.comparators.LongComparator; /** @@ -328,8 +327,8 @@ public abstract class LongValuesSource implements SegmentCacheable { @Override public FieldComparator newComparator( - String fieldname, int numHits, int sortPos, boolean reversed) { - return new LongComparator(numHits, fieldname, missingValue, reversed, sortPos) { + String fieldname, int numHits, boolean enableSkipping, boolean reversed) { + return new LongComparator(numHits, fieldname, missingValue, reversed, false) { @Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { LongValuesHolder holder = new LongValuesHolder(); @@ -344,11 +343,6 @@ public abstract class LongValuesSource implements SegmentCacheable { return asNumericDocValues(holder); } - @Override - protected PointValues getPointValues(LeafReaderContext context, String field) { - return null; - } - @Override public void setScorer(Scorable scorer) throws IOException { holder.values = producer.getValues(ctx, DoubleValuesSource.fromScorer(scorer)); diff --git a/lucene/core/src/java/org/apache/lucene/search/SortField.java b/lucene/core/src/java/org/apache/lucene/search/SortField.java index 18154136d2f..76815c5fffa 100644 --- a/lucene/core/src/java/org/apache/lucene/search/SortField.java +++ b/lucene/core/src/java/org/apache/lucene/search/SortField.java @@ -495,12 +495,11 @@ public class SortField { * * @lucene.experimental * @param numHits number of top hits the queue will store - * @param sortPos position of this SortField within {@link Sort}. The comparator is primary if - * sortPos==0, secondary if sortPos==1, etc. Some comparators can optimize themselves when - * they are the primary sort. + * @param enableSkipping true if the comparator can skip documents via {@link + * LeafFieldComparator#competitiveIterator()} * @return {@link FieldComparator} to use when sorting */ - public FieldComparator getComparator(final int numHits, final int sortPos) { + public FieldComparator getComparator(final int numHits, boolean enableSkipping) { final FieldComparator fieldComparator; switch (type) { case SCORE: @@ -508,31 +507,32 @@ public class SortField { break; case DOC: - fieldComparator = new DocComparator(numHits, reverse, sortPos); + fieldComparator = new DocComparator(numHits, reverse, enableSkipping); break; case INT: fieldComparator = - new IntComparator(numHits, field, (Integer) missingValue, reverse, sortPos); + new IntComparator(numHits, field, (Integer) missingValue, reverse, enableSkipping); break; case FLOAT: fieldComparator = - new FloatComparator(numHits, field, (Float) missingValue, reverse, sortPos); + new FloatComparator(numHits, field, (Float) missingValue, reverse, enableSkipping); break; case LONG: - fieldComparator = new LongComparator(numHits, field, (Long) missingValue, reverse, sortPos); + fieldComparator = + new LongComparator(numHits, field, (Long) missingValue, reverse, enableSkipping); break; case DOUBLE: fieldComparator = - new DoubleComparator(numHits, field, (Double) missingValue, reverse, sortPos); + new DoubleComparator(numHits, field, (Double) missingValue, reverse, enableSkipping); break; case CUSTOM: assert comparatorSource != null; - fieldComparator = comparatorSource.newComparator(field, numHits, sortPos, reverse); + fieldComparator = comparatorSource.newComparator(field, numHits, enableSkipping, reverse); break; case STRING: diff --git a/lucene/core/src/java/org/apache/lucene/search/SortedNumericSortField.java b/lucene/core/src/java/org/apache/lucene/search/SortedNumericSortField.java index e01461ec4aa..38de65414eb 100644 --- a/lucene/core/src/java/org/apache/lucene/search/SortedNumericSortField.java +++ b/lucene/core/src/java/org/apache/lucene/search/SortedNumericSortField.java @@ -22,7 +22,6 @@ import org.apache.lucene.index.IndexSorter; import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.PointValues; import org.apache.lucene.index.SortFieldProvider; import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.search.comparators.DoubleComparator; @@ -242,12 +241,21 @@ public class SortedNumericSortField extends SortField { } @Override - public FieldComparator getComparator(int numHits, int sortPos) { + public FieldComparator getComparator(int numHits, boolean enableSkipping) { final FieldComparator fieldComparator; + // we can use sort optimization with points if selector is MIN or MAX, + // because we can still build successful iterator over points in this case. + boolean isMinOrMax = + selector == SortedNumericSelector.Type.MAX || selector == SortedNumericSelector.Type.MIN; switch (type) { case INT: fieldComparator = - new IntComparator(numHits, getField(), (Integer) missingValue, reverse, sortPos) { + new IntComparator( + numHits, + getField(), + (Integer) missingValue, + reverse, + enableSkipping && isMinOrMax) { @Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { @@ -258,25 +266,14 @@ public class SortedNumericSortField extends SortField { return SortedNumericSelector.wrap( DocValues.getSortedNumeric(context.reader(), field), selector, type); } - // we can use sort optimization with points if selector is MIN or MAX, - // because we can still build successful iterator over points in this case. - @Override - protected PointValues getPointValues(LeafReaderContext context, String field) - throws IOException { - if (selector == SortedNumericSelector.Type.MAX - || selector == SortedNumericSelector.Type.MIN) { - return super.getPointValues(context, field); - } else { - return null; - } - } }; } }; break; case FLOAT: fieldComparator = - new FloatComparator(numHits, getField(), (Float) missingValue, reverse, sortPos) { + new FloatComparator( + numHits, getField(), (Float) missingValue, reverse, enableSkipping && isMinOrMax) { @Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { @@ -287,25 +284,14 @@ public class SortedNumericSortField extends SortField { return SortedNumericSelector.wrap( DocValues.getSortedNumeric(context.reader(), field), selector, type); } - // we can use sort optimization with points if selector is MIN or MAX, - // because we can still build successful iterator over points in this case. - @Override - protected PointValues getPointValues(LeafReaderContext context, String field) - throws IOException { - if (selector == SortedNumericSelector.Type.MAX - || selector == SortedNumericSelector.Type.MIN) { - return super.getPointValues(context, field); - } else { - return null; - } - } }; } }; break; case LONG: fieldComparator = - new LongComparator(numHits, getField(), (Long) missingValue, reverse, sortPos) { + new LongComparator( + numHits, getField(), (Long) missingValue, reverse, enableSkipping && isMinOrMax) { @Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { @@ -316,25 +302,14 @@ public class SortedNumericSortField extends SortField { return SortedNumericSelector.wrap( DocValues.getSortedNumeric(context.reader(), field), selector, type); } - // we can use sort optimization with points if selector is MIN or MAX, - // because we can still build successful iterator over points in this case. - @Override - protected PointValues getPointValues(LeafReaderContext context, String field) - throws IOException { - if (selector == SortedNumericSelector.Type.MAX - || selector == SortedNumericSelector.Type.MIN) { - return super.getPointValues(context, field); - } else { - return null; - } - } }; } }; break; case DOUBLE: fieldComparator = - new DoubleComparator(numHits, getField(), (Double) missingValue, reverse, sortPos) { + new DoubleComparator( + numHits, getField(), (Double) missingValue, reverse, enableSkipping && isMinOrMax) { @Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { @@ -345,18 +320,6 @@ public class SortedNumericSortField extends SortField { return SortedNumericSelector.wrap( DocValues.getSortedNumeric(context.reader(), field), selector, type); } - // we can use sort optimization with points if selector is MIN or MAX, - // because we can still build successful iterator over points in this case. - @Override - protected PointValues getPointValues(LeafReaderContext context, String field) - throws IOException { - if (selector == SortedNumericSelector.Type.MAX - || selector == SortedNumericSelector.Type.MIN) { - return super.getPointValues(context, field); - } else { - return null; - } - } }; } }; diff --git a/lucene/core/src/java/org/apache/lucene/search/SortedSetSortField.java b/lucene/core/src/java/org/apache/lucene/search/SortedSetSortField.java index b09bd415a64..a44e4a84e89 100644 --- a/lucene/core/src/java/org/apache/lucene/search/SortedSetSortField.java +++ b/lucene/core/src/java/org/apache/lucene/search/SortedSetSortField.java @@ -177,7 +177,7 @@ public class SortedSetSortField extends SortField { } @Override - public FieldComparator getComparator(int numHits, int sortPos) { + public FieldComparator getComparator(int numHits, boolean enableSkipping) { return new FieldComparator.TermOrdValComparator( numHits, getField(), missingValue == STRING_LAST) { @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/TopDocs.java b/lucene/core/src/java/org/apache/lucene/search/TopDocs.java index 0b468a4434c..7871db906a8 100644 --- a/lucene/core/src/java/org/apache/lucene/search/TopDocs.java +++ b/lucene/core/src/java/org/apache/lucene/search/TopDocs.java @@ -159,7 +159,7 @@ public class TopDocs { reverseMul = new int[sortFields.length]; for (int compIDX = 0; compIDX < sortFields.length; compIDX++) { final SortField sortField = sortFields[compIDX]; - comparators[compIDX] = sortField.getComparator(1, compIDX); + comparators[compIDX] = sortField.getComparator(1, compIDX == 0); reverseMul[compIDX] = sortField.getReverse() ? -1 : 1; } } diff --git a/lucene/core/src/java/org/apache/lucene/search/comparators/DocComparator.java b/lucene/core/src/java/org/apache/lucene/search/comparators/DocComparator.java index 7b8845bec4f..53b1c584062 100644 --- a/lucene/core/src/java/org/apache/lucene/search/comparators/DocComparator.java +++ b/lucene/core/src/java/org/apache/lucene/search/comparators/DocComparator.java @@ -35,10 +35,10 @@ public class DocComparator extends FieldComparator { private boolean hitsThresholdReached; /** Creates a new comparator based on document ids for {@code numHits} */ - public DocComparator(int numHits, boolean reverse, int sortPost) { + public DocComparator(int numHits, boolean reverse, boolean enableSkipping) { this.docIDs = new int[numHits]; // skipping functionality is enabled if we are sorting by _doc in asc order as a primary sort - this.enableSkipping = (reverse == false && sortPost == 0); + this.enableSkipping = (reverse == false && enableSkipping); } @Override diff --git a/lucene/core/src/java/org/apache/lucene/search/comparators/DoubleComparator.java b/lucene/core/src/java/org/apache/lucene/search/comparators/DoubleComparator.java index 62f46d948a1..68fc72c7472 100644 --- a/lucene/core/src/java/org/apache/lucene/search/comparators/DoubleComparator.java +++ b/lucene/core/src/java/org/apache/lucene/search/comparators/DoubleComparator.java @@ -32,8 +32,8 @@ public class DoubleComparator extends NumericComparator { protected double bottom; public DoubleComparator( - int numHits, String field, Double missingValue, boolean reverse, int sortPos) { - super(field, missingValue != null ? missingValue : 0.0, reverse, sortPos, Double.BYTES); + int numHits, String field, Double missingValue, boolean reverse, boolean enableSkipping) { + super(field, missingValue != null ? missingValue : 0.0, reverse, enableSkipping, Double.BYTES); values = new double[numHits]; } diff --git a/lucene/core/src/java/org/apache/lucene/search/comparators/FloatComparator.java b/lucene/core/src/java/org/apache/lucene/search/comparators/FloatComparator.java index ed72db3afcc..8bb9a22417d 100644 --- a/lucene/core/src/java/org/apache/lucene/search/comparators/FloatComparator.java +++ b/lucene/core/src/java/org/apache/lucene/search/comparators/FloatComparator.java @@ -32,8 +32,8 @@ public class FloatComparator extends NumericComparator { protected float bottom; public FloatComparator( - int numHits, String field, Float missingValue, boolean reverse, int sortPos) { - super(field, missingValue != null ? missingValue : 0.0f, reverse, sortPos, Float.BYTES); + int numHits, String field, Float missingValue, boolean reverse, boolean enableSkipping) { + super(field, missingValue != null ? missingValue : 0.0f, reverse, enableSkipping, Float.BYTES); values = new float[numHits]; } diff --git a/lucene/core/src/java/org/apache/lucene/search/comparators/IntComparator.java b/lucene/core/src/java/org/apache/lucene/search/comparators/IntComparator.java index 9f2f07b3a73..d3576e9ee07 100644 --- a/lucene/core/src/java/org/apache/lucene/search/comparators/IntComparator.java +++ b/lucene/core/src/java/org/apache/lucene/search/comparators/IntComparator.java @@ -32,8 +32,8 @@ public class IntComparator extends NumericComparator { protected int bottom; public IntComparator( - int numHits, String field, Integer missingValue, boolean reverse, int sortPos) { - super(field, missingValue != null ? missingValue : 0, reverse, sortPos, Integer.BYTES); + int numHits, String field, Integer missingValue, boolean reverse, boolean enableSkipping) { + super(field, missingValue != null ? missingValue : 0, reverse, enableSkipping, Integer.BYTES); values = new int[numHits]; } diff --git a/lucene/core/src/java/org/apache/lucene/search/comparators/LongComparator.java b/lucene/core/src/java/org/apache/lucene/search/comparators/LongComparator.java index 471de2d4220..a96a163b44e 100644 --- a/lucene/core/src/java/org/apache/lucene/search/comparators/LongComparator.java +++ b/lucene/core/src/java/org/apache/lucene/search/comparators/LongComparator.java @@ -32,8 +32,8 @@ public class LongComparator extends NumericComparator { protected long bottom; public LongComparator( - int numHits, String field, Long missingValue, boolean reverse, int sortPos) { - super(field, missingValue != null ? missingValue : 0L, reverse, sortPos, Long.BYTES); + int numHits, String field, Long missingValue, boolean reverse, boolean enableSkipping) { + super(field, missingValue != null ? missingValue : 0L, reverse, enableSkipping, Long.BYTES); values = new long[numHits]; } diff --git a/lucene/core/src/java/org/apache/lucene/search/comparators/NumericComparator.java b/lucene/core/src/java/org/apache/lucene/search/comparators/NumericComparator.java index d8a597d9451..a44583fceba 100644 --- a/lucene/core/src/java/org/apache/lucene/search/comparators/NumericComparator.java +++ b/lucene/core/src/java/org/apache/lucene/search/comparators/NumericComparator.java @@ -55,12 +55,12 @@ public abstract class NumericComparator extends FieldComparato private boolean canSkipDocuments; protected NumericComparator( - String field, T missingValue, boolean reverse, int sortPos, int bytesCount) { + String field, T missingValue, boolean reverse, boolean enableSkipping, int bytesCount) { this.field = field; this.missingValue = missingValue; this.reverse = reverse; // skipping functionality is only relevant for primary sort - this.canSkipDocuments = (sortPos == 0); + this.canSkipDocuments = enableSkipping; this.bytesCount = bytesCount; this.bytesComparator = ArrayUtil.getUnsignedComparator(bytesCount); } @@ -97,7 +97,7 @@ public abstract class NumericComparator extends FieldComparato public NumericLeafComparator(LeafReaderContext context) throws IOException { this.docValues = getNumericDocValues(context, field); - this.pointValues = canSkipDocuments ? getPointValues(context, field) : null; + this.pointValues = canSkipDocuments ? context.reader().getPointValues(field) : null; if (pointValues != null) { FieldInfo info = context.reader().getFieldInfos().fieldInfo(field); if (info == null || info.getPointDimensionCount() == 0) { @@ -138,10 +138,9 @@ public abstract class NumericComparator extends FieldComparato /** * Retrieves the NumericDocValues for the field in this segment * - *

If you override this method, you must also override {@link - * #getPointValues(LeafReaderContext, String)} This class uses sort optimization that leverages - * points to filter out non-competitive matches, which relies on the assumption that points and - * doc values record the same information. + *

If you override this method, you should probably always disable skipping as the comparator + * uses values from the points index to build its competitive iterators, and assumes that the + * values in doc values and points are the same. * * @param context – reader context * @param field - field name @@ -153,26 +152,6 @@ public abstract class NumericComparator extends FieldComparato return DocValues.getNumeric(context.reader(), field); } - /** - * Retrieves point values for the field in this segment - * - *

If you override this method, you must also override {@link - * #getNumericDocValues(LeafReaderContext, String)} This class uses sort optimization that - * leverages points to filter out non-competitive matches, which relies on the assumption that - * points and doc values record the same information. Return {@code null} even if no points - * implementation is available, in this case sort optimization with points will be disabled. - * - * @param context – reader context - * @param field - field name - * @return point values for the field in this segment if they are available or {@code null} if - * sort optimization with points should be disabled. - * @throws IOException If there is a low-level I/O error - */ - protected PointValues getPointValues(LeafReaderContext context, String field) - throws IOException { - return context.reader().getPointValues(field); - } - @Override public void setBottom(int slot) throws IOException { queueFull = true; // if we are setting bottom, it means that we have collected enough hits diff --git a/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java b/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java index 162c143e78c..c987ecfaaab 100644 --- a/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java +++ b/lucene/core/src/test/org/apache/lucene/search/JustCompileSearch.java @@ -118,7 +118,7 @@ final class JustCompileSearch { @Override public FieldComparator newComparator( - String fieldname, int numHits, int sortPos, boolean reversed) { + String fieldname, int numHits, boolean enableSkipping, boolean reversed) { throw new UnsupportedOperationException(UNSUPPORTED_MSG); } } diff --git a/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java b/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java index 2cb8e3a6477..1b7881f0244 100644 --- a/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java +++ b/lucene/core/src/test/org/apache/lucene/search/TestElevationComparator.java @@ -151,7 +151,7 @@ class ElevationComparatorSource extends FieldComparatorSource { @Override public FieldComparator newComparator( - final String fieldname, final int numHits, int sortPos, boolean reversed) { + final String fieldname, final int numHits, boolean enableSkipping, boolean reversed) { return new FieldComparator() { private final int[] values = new int[numHits]; diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/AllGroupHeadsCollector.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/AllGroupHeadsCollector.java index 56a2d3d41cd..8bfe9f144f4 100644 --- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/AllGroupHeadsCollector.java +++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/AllGroupHeadsCollector.java @@ -258,7 +258,7 @@ public abstract class AllGroupHeadsCollector extends SimpleCollector { comparators = new FieldComparator[sortFields.length]; leafComparators = new LeafFieldComparator[sortFields.length]; for (int i = 0; i < sortFields.length; i++) { - comparators[i] = sortFields[i].getComparator(1, i); + comparators[i] = sortFields[i].getComparator(1, false); leafComparators[i] = comparators[i].getLeafComparator(context); leafComparators[i].setScorer(scorer); leafComparators[i].copy(0, doc); diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java index 226aca061d8..9ead686831e 100644 --- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java +++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/BlockGroupingCollector.java @@ -240,7 +240,7 @@ public class BlockGroupingCollector extends SimpleCollector { reversed = new int[sortFields.length]; for (int i = 0; i < sortFields.length; i++) { final SortField sortField = sortFields[i]; - comparators[i] = sortField.getComparator(topNGroups, i); + comparators[i] = sortField.getComparator(topNGroups, false); reversed[i] = sortField.getReverse() ? -1 : 1; } } diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.java index 6873eb350dd..9bcda62592e 100644 --- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.java +++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.java @@ -90,7 +90,7 @@ public class FirstPassGroupingCollector extends SimpleCollector { // use topNGroups + 1 so we have a spare slot to use for comparing (tracked by // this.spareSlot): - comparators[i] = sortField.getComparator(topNGroups + 1, i); + comparators[i] = sortField.getComparator(topNGroups + 1, false); reversed[i] = sortField.getReverse() ? -1 : 1; } diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java index d3221358e17..087cae755fc 100644 --- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java +++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/SearchGroup.java @@ -176,7 +176,7 @@ public class SearchGroup { reversed = new int[sortFields.length]; for (int compIDX = 0; compIDX < sortFields.length; compIDX++) { final SortField sortField = sortFields[compIDX]; - comparators[compIDX] = sortField.getComparator(1, compIDX); + comparators[compIDX] = sortField.getComparator(1, false); reversed[compIDX] = sortField.getReverse() ? -1 : 1; } } diff --git a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinSortField.java b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinSortField.java index b97a3caa969..20307ba73e6 100644 --- a/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinSortField.java +++ b/lucene/join/src/java/org/apache/lucene/search/join/ToParentBlockJoinSortField.java @@ -23,7 +23,6 @@ import org.apache.lucene.index.DocValues; import org.apache.lucene.index.FilterNumericDocValues; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; -import org.apache.lucene.index.PointValues; import org.apache.lucene.index.SortedDocValues; import org.apache.lucene.index.SortedNumericDocValues; import org.apache.lucene.index.SortedSetDocValues; @@ -112,18 +111,18 @@ public class ToParentBlockJoinSortField extends SortField { } @Override - public FieldComparator getComparator(int numHits, int sortPos) { + public FieldComparator getComparator(int numHits, boolean enableSkipping) { switch (getType()) { case STRING: return getStringComparator(numHits); case DOUBLE: - return getDoubleComparator(numHits, sortPos); + return getDoubleComparator(numHits); case FLOAT: - return getFloatComparator(numHits, sortPos); + return getFloatComparator(numHits); case LONG: - return getLongComparator(numHits, sortPos); + return getLongComparator(numHits); case INT: - return getIntComparator(numHits, sortPos); + return getIntComparator(numHits); case CUSTOM: case DOC: case REWRITEABLE: @@ -154,8 +153,8 @@ public class ToParentBlockJoinSortField extends SortField { }; } - private FieldComparator getIntComparator(int numHits, int sortPos) { - return new IntComparator(numHits, getField(), (Integer) missingValue, getReverse(), sortPos) { + private FieldComparator getIntComparator(int numHits) { + return new IntComparator(numHits, getField(), (Integer) missingValue, getReverse(), false) { @Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { return new IntLeafComparator(context) { @@ -173,18 +172,13 @@ public class ToParentBlockJoinSortField extends SortField { } return BlockJoinSelector.wrap(sortedNumeric, type, parents, toIter(children)); } - // no sort optimization with points - @Override - protected PointValues getPointValues(LeafReaderContext context, String field) { - return null; - } }; } }; } - private FieldComparator getLongComparator(int numHits, int sortPos) { - return new LongComparator(numHits, getField(), (Long) missingValue, getReverse(), sortPos) { + private FieldComparator getLongComparator(int numHits) { + return new LongComparator(numHits, getField(), (Long) missingValue, getReverse(), false) { @Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { return new LongLeafComparator(context) { @@ -202,18 +196,13 @@ public class ToParentBlockJoinSortField extends SortField { } return BlockJoinSelector.wrap(sortedNumeric, type, parents, toIter(children)); } - // no sort optimization with points - @Override - protected PointValues getPointValues(LeafReaderContext context, String field) { - return null; - } }; } }; } - private FieldComparator getFloatComparator(int numHits, int sortPos) { - return new FloatComparator(numHits, getField(), (Float) missingValue, getReverse(), sortPos) { + private FieldComparator getFloatComparator(int numHits) { + return new FloatComparator(numHits, getField(), (Float) missingValue, getReverse(), false) { @Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { return new FloatLeafComparator(context) { @@ -238,20 +227,14 @@ public class ToParentBlockJoinSortField extends SortField { } }; } - // no sort optimization with points - @Override - protected PointValues getPointValues(LeafReaderContext context, String field) { - return null; - } }; } ; }; } - private FieldComparator getDoubleComparator(int numHits, int sortPost) { - return new DoubleComparator( - numHits, getField(), (Double) missingValue, getReverse(), sortPost) { + private FieldComparator getDoubleComparator(int numHits) { + return new DoubleComparator(numHits, getField(), (Double) missingValue, getReverse(), false) { @Override public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException { return new DoubleLeafComparator(context) { @@ -276,11 +259,6 @@ public class ToParentBlockJoinSortField extends SortField { } }; } - // no sort optimization with points - @Override - protected PointValues getPointValues(LeafReaderContext context, String field) { - return null; - } }; } }; diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java index 88658389c42..1320f760894 100644 --- a/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java +++ b/lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java @@ -381,7 +381,7 @@ public abstract class ValueSource { @Override public FieldComparator newComparator( - String fieldname, int numHits, int sortPos, boolean reversed) { + String fieldname, int numHits, boolean enableSkipping, boolean reversed) { return new ValueSourceComparator(context, numHits); } } diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java index a43debdfa4c..829ed712469 100644 --- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java +++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/IndexSortSortedNumericDocValuesRangeQuery.java @@ -247,7 +247,8 @@ public class IndexSortSortedNumericDocValuesRangeQuery extends Query { private static ValueComparator loadComparator( SortField sortField, long topValue, LeafReaderContext context) throws IOException { @SuppressWarnings("unchecked") - FieldComparator fieldComparator = (FieldComparator) sortField.getComparator(1, 0); + FieldComparator fieldComparator = + (FieldComparator) sortField.getComparator(1, false); fieldComparator.setTopValue(topValue); LeafFieldComparator leafFieldComparator = fieldComparator.getLeafComparator(context); diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointOutsideSortField.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointOutsideSortField.java index c7605e34187..8e75e8026c1 100644 --- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointOutsideSortField.java +++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointOutsideSortField.java @@ -41,7 +41,7 @@ final class Geo3DPointOutsideSortField extends SortField { } @Override - public FieldComparator getComparator(int numHits, int sortPos) { + public FieldComparator getComparator(int numHits, boolean enableSkipping) { return new Geo3DPointOutsideDistanceComparator(getField(), planetModel, distanceShape, numHits); } diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointSortField.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointSortField.java index 0e5dba512ae..2b7c2529a7e 100644 --- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointSortField.java +++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/Geo3DPointSortField.java @@ -41,7 +41,7 @@ final class Geo3DPointSortField extends SortField { } @Override - public FieldComparator getComparator(int numHits, int sortPos) { + public FieldComparator getComparator(int numHits, boolean enableSkipping) { return new Geo3DPointDistanceComparator(getField(), planetModel, distanceShape, numHits); }