mirror of https://github.com/apache/lucene.git
LUCENE-10377: Replace 'sortPos' with 'enableSkipping' in SortField.getComparator() (#603)
The sort position parameter in SortField.getComparator() is only ever used to determine whether or not skipping should be enabled on a given comparator, so the parameter name should reflect that. This commit also explicitly disables skipping in a number of cases where it is never used, in particular CheckIndex and the grouping collectors.
This commit is contained in:
parent
457367e9b7
commit
2e2c4818d1
|
@ -63,6 +63,10 @@ API Changes
|
||||||
|
|
||||||
* LUCENE-10349: WordListLoader methods now return unmodifiable CharArraySets. (Uwe Schindler)
|
* 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
|
New Features
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
@ -187,6 +191,9 @@ Bug Fixes
|
||||||
* LLUCENE-10353: Add random null injection to TestRandomChains. (Robert Muir,
|
* LLUCENE-10353: Add random null injection to TestRandomChains. (Robert Muir,
|
||||||
Uwe Schindler)
|
Uwe Schindler)
|
||||||
|
|
||||||
|
* LUCENE-10377: CheckIndex could incorrectly throw an error when checking index sorts
|
||||||
|
defined on older indexes. (Alan Woodward)
|
||||||
|
|
||||||
Other
|
Other
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ final class FeatureSortField extends SortField {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<?> getComparator(int numHits, int sortPos) {
|
public FieldComparator<?> getComparator(int numHits, boolean enableSkipping) {
|
||||||
return new FeatureComparator(numHits, getField(), featureName);
|
return new FeatureComparator(numHits, getField(), featureName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ final class LatLonPointSortField extends SortField {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<?> getComparator(int numHits, int sortPos) {
|
public FieldComparator<?> getComparator(int numHits, boolean enableSkipping) {
|
||||||
return new LatLonPointDistanceComparator(getField(), latitude, longitude, numHits);
|
return new LatLonPointDistanceComparator(getField(), latitude, longitude, numHits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ final class XYPointSortField extends SortField {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<?> getComparator(int numHits, int sortPos) {
|
public FieldComparator<?> getComparator(int numHits, boolean enableSkipping) {
|
||||||
return new XYPointDistanceComparator(getField(), x, y, numHits);
|
return new XYPointDistanceComparator(getField(), x, y, numHits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1107,7 +1107,7 @@ public final class CheckIndex implements Closeable {
|
||||||
|
|
||||||
for (int i = 0; i < fields.length; i++) {
|
for (int i = 0; i < fields.length; i++) {
|
||||||
reverseMul[i] = fields[i].getReverse() ? -1 : 1;
|
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();
|
int maxDoc = reader.maxDoc();
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.apache.lucene.index.DocValues;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.LeafReaderContext;
|
import org.apache.lucene.index.LeafReaderContext;
|
||||||
import org.apache.lucene.index.NumericDocValues;
|
import org.apache.lucene.index.NumericDocValues;
|
||||||
import org.apache.lucene.index.PointValues;
|
|
||||||
import org.apache.lucene.search.comparators.DoubleComparator;
|
import org.apache.lucene.search.comparators.DoubleComparator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -483,8 +482,8 @@ public abstract class DoubleValuesSource implements SegmentCacheable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<Double> newComparator(
|
public FieldComparator<Double> newComparator(
|
||||||
String fieldname, int numHits, int sortPos, boolean reversed) {
|
String fieldname, int numHits, boolean enableSkipping, boolean reversed) {
|
||||||
return new DoubleComparator(numHits, fieldname, missingValue, reversed, sortPos) {
|
return new DoubleComparator(numHits, fieldname, missingValue, reversed, false) {
|
||||||
@Override
|
@Override
|
||||||
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
|
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
|
||||||
DoubleValuesHolder holder = new DoubleValuesHolder();
|
DoubleValuesHolder holder = new DoubleValuesHolder();
|
||||||
|
@ -499,11 +498,6 @@ public abstract class DoubleValuesSource implements SegmentCacheable {
|
||||||
return asNumericDocValues(holder, Double::doubleToLongBits);
|
return asNumericDocValues(holder, Double::doubleToLongBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected PointValues getPointValues(LeafReaderContext context, String field) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setScorer(Scorable scorer) throws IOException {
|
public void setScorer(Scorable scorer) throws IOException {
|
||||||
holder.values = producer.getValues(ctx, fromScorer(scorer));
|
holder.values = producer.getValues(ctx, fromScorer(scorer));
|
||||||
|
|
|
@ -30,5 +30,5 @@ public abstract class FieldComparatorSource {
|
||||||
* @return FieldComparator.
|
* @return FieldComparator.
|
||||||
*/
|
*/
|
||||||
public abstract FieldComparator<?> newComparator(
|
public abstract FieldComparator<?> newComparator(
|
||||||
String fieldname, int numHits, int sortPos, boolean reversed);
|
String fieldname, int numHits, boolean enableSkipping, boolean reversed);
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ public abstract class FieldValueHitQueue<T extends FieldValueHitQueue.Entry>
|
||||||
for (int i = 0; i < numComparators; ++i) {
|
for (int i = 0; i < numComparators; ++i) {
|
||||||
SortField field = fields[i];
|
SortField field = fields[i];
|
||||||
reverseMul[i] = field.reverse ? -1 : 1;
|
reverseMul[i] = field.reverse ? -1 : 1;
|
||||||
comparators[i] = field.getComparator(size, i);
|
comparators[i] = field.getComparator(size, i == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ import java.util.Objects;
|
||||||
import org.apache.lucene.index.DocValues;
|
import org.apache.lucene.index.DocValues;
|
||||||
import org.apache.lucene.index.LeafReaderContext;
|
import org.apache.lucene.index.LeafReaderContext;
|
||||||
import org.apache.lucene.index.NumericDocValues;
|
import org.apache.lucene.index.NumericDocValues;
|
||||||
import org.apache.lucene.index.PointValues;
|
|
||||||
import org.apache.lucene.search.comparators.LongComparator;
|
import org.apache.lucene.search.comparators.LongComparator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -328,8 +327,8 @@ public abstract class LongValuesSource implements SegmentCacheable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<Long> newComparator(
|
public FieldComparator<Long> newComparator(
|
||||||
String fieldname, int numHits, int sortPos, boolean reversed) {
|
String fieldname, int numHits, boolean enableSkipping, boolean reversed) {
|
||||||
return new LongComparator(numHits, fieldname, missingValue, reversed, sortPos) {
|
return new LongComparator(numHits, fieldname, missingValue, reversed, false) {
|
||||||
@Override
|
@Override
|
||||||
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
|
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
|
||||||
LongValuesHolder holder = new LongValuesHolder();
|
LongValuesHolder holder = new LongValuesHolder();
|
||||||
|
@ -344,11 +343,6 @@ public abstract class LongValuesSource implements SegmentCacheable {
|
||||||
return asNumericDocValues(holder);
|
return asNumericDocValues(holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected PointValues getPointValues(LeafReaderContext context, String field) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setScorer(Scorable scorer) throws IOException {
|
public void setScorer(Scorable scorer) throws IOException {
|
||||||
holder.values = producer.getValues(ctx, DoubleValuesSource.fromScorer(scorer));
|
holder.values = producer.getValues(ctx, DoubleValuesSource.fromScorer(scorer));
|
||||||
|
|
|
@ -495,12 +495,11 @@ public class SortField {
|
||||||
*
|
*
|
||||||
* @lucene.experimental
|
* @lucene.experimental
|
||||||
* @param numHits number of top hits the queue will store
|
* @param numHits number of top hits the queue will store
|
||||||
* @param sortPos position of this SortField within {@link Sort}. The comparator is primary if
|
* @param enableSkipping true if the comparator can skip documents via {@link
|
||||||
* sortPos==0, secondary if sortPos==1, etc. Some comparators can optimize themselves when
|
* LeafFieldComparator#competitiveIterator()}
|
||||||
* they are the primary sort.
|
|
||||||
* @return {@link FieldComparator} to use when sorting
|
* @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;
|
final FieldComparator<?> fieldComparator;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SCORE:
|
case SCORE:
|
||||||
|
@ -508,31 +507,32 @@ public class SortField {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DOC:
|
case DOC:
|
||||||
fieldComparator = new DocComparator(numHits, reverse, sortPos);
|
fieldComparator = new DocComparator(numHits, reverse, enableSkipping);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INT:
|
case INT:
|
||||||
fieldComparator =
|
fieldComparator =
|
||||||
new IntComparator(numHits, field, (Integer) missingValue, reverse, sortPos);
|
new IntComparator(numHits, field, (Integer) missingValue, reverse, enableSkipping);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FLOAT:
|
case FLOAT:
|
||||||
fieldComparator =
|
fieldComparator =
|
||||||
new FloatComparator(numHits, field, (Float) missingValue, reverse, sortPos);
|
new FloatComparator(numHits, field, (Float) missingValue, reverse, enableSkipping);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LONG:
|
case LONG:
|
||||||
fieldComparator = new LongComparator(numHits, field, (Long) missingValue, reverse, sortPos);
|
fieldComparator =
|
||||||
|
new LongComparator(numHits, field, (Long) missingValue, reverse, enableSkipping);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DOUBLE:
|
case DOUBLE:
|
||||||
fieldComparator =
|
fieldComparator =
|
||||||
new DoubleComparator(numHits, field, (Double) missingValue, reverse, sortPos);
|
new DoubleComparator(numHits, field, (Double) missingValue, reverse, enableSkipping);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CUSTOM:
|
case CUSTOM:
|
||||||
assert comparatorSource != null;
|
assert comparatorSource != null;
|
||||||
fieldComparator = comparatorSource.newComparator(field, numHits, sortPos, reverse);
|
fieldComparator = comparatorSource.newComparator(field, numHits, enableSkipping, reverse);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STRING:
|
case STRING:
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.apache.lucene.index.IndexSorter;
|
||||||
import org.apache.lucene.index.LeafReader;
|
import org.apache.lucene.index.LeafReader;
|
||||||
import org.apache.lucene.index.LeafReaderContext;
|
import org.apache.lucene.index.LeafReaderContext;
|
||||||
import org.apache.lucene.index.NumericDocValues;
|
import org.apache.lucene.index.NumericDocValues;
|
||||||
import org.apache.lucene.index.PointValues;
|
|
||||||
import org.apache.lucene.index.SortFieldProvider;
|
import org.apache.lucene.index.SortFieldProvider;
|
||||||
import org.apache.lucene.index.SortedNumericDocValues;
|
import org.apache.lucene.index.SortedNumericDocValues;
|
||||||
import org.apache.lucene.search.comparators.DoubleComparator;
|
import org.apache.lucene.search.comparators.DoubleComparator;
|
||||||
|
@ -242,12 +241,21 @@ public class SortedNumericSortField extends SortField {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<?> getComparator(int numHits, int sortPos) {
|
public FieldComparator<?> getComparator(int numHits, boolean enableSkipping) {
|
||||||
final FieldComparator<?> fieldComparator;
|
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) {
|
switch (type) {
|
||||||
case INT:
|
case INT:
|
||||||
fieldComparator =
|
fieldComparator =
|
||||||
new IntComparator(numHits, getField(), (Integer) missingValue, reverse, sortPos) {
|
new IntComparator(
|
||||||
|
numHits,
|
||||||
|
getField(),
|
||||||
|
(Integer) missingValue,
|
||||||
|
reverse,
|
||||||
|
enableSkipping && isMinOrMax) {
|
||||||
@Override
|
@Override
|
||||||
public LeafFieldComparator getLeafComparator(LeafReaderContext context)
|
public LeafFieldComparator getLeafComparator(LeafReaderContext context)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -258,25 +266,14 @@ public class SortedNumericSortField extends SortField {
|
||||||
return SortedNumericSelector.wrap(
|
return SortedNumericSelector.wrap(
|
||||||
DocValues.getSortedNumeric(context.reader(), field), selector, type);
|
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;
|
break;
|
||||||
case FLOAT:
|
case FLOAT:
|
||||||
fieldComparator =
|
fieldComparator =
|
||||||
new FloatComparator(numHits, getField(), (Float) missingValue, reverse, sortPos) {
|
new FloatComparator(
|
||||||
|
numHits, getField(), (Float) missingValue, reverse, enableSkipping && isMinOrMax) {
|
||||||
@Override
|
@Override
|
||||||
public LeafFieldComparator getLeafComparator(LeafReaderContext context)
|
public LeafFieldComparator getLeafComparator(LeafReaderContext context)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -287,25 +284,14 @@ public class SortedNumericSortField extends SortField {
|
||||||
return SortedNumericSelector.wrap(
|
return SortedNumericSelector.wrap(
|
||||||
DocValues.getSortedNumeric(context.reader(), field), selector, type);
|
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;
|
break;
|
||||||
case LONG:
|
case LONG:
|
||||||
fieldComparator =
|
fieldComparator =
|
||||||
new LongComparator(numHits, getField(), (Long) missingValue, reverse, sortPos) {
|
new LongComparator(
|
||||||
|
numHits, getField(), (Long) missingValue, reverse, enableSkipping && isMinOrMax) {
|
||||||
@Override
|
@Override
|
||||||
public LeafFieldComparator getLeafComparator(LeafReaderContext context)
|
public LeafFieldComparator getLeafComparator(LeafReaderContext context)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -316,25 +302,14 @@ public class SortedNumericSortField extends SortField {
|
||||||
return SortedNumericSelector.wrap(
|
return SortedNumericSelector.wrap(
|
||||||
DocValues.getSortedNumeric(context.reader(), field), selector, type);
|
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;
|
break;
|
||||||
case DOUBLE:
|
case DOUBLE:
|
||||||
fieldComparator =
|
fieldComparator =
|
||||||
new DoubleComparator(numHits, getField(), (Double) missingValue, reverse, sortPos) {
|
new DoubleComparator(
|
||||||
|
numHits, getField(), (Double) missingValue, reverse, enableSkipping && isMinOrMax) {
|
||||||
@Override
|
@Override
|
||||||
public LeafFieldComparator getLeafComparator(LeafReaderContext context)
|
public LeafFieldComparator getLeafComparator(LeafReaderContext context)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -345,18 +320,6 @@ public class SortedNumericSortField extends SortField {
|
||||||
return SortedNumericSelector.wrap(
|
return SortedNumericSelector.wrap(
|
||||||
DocValues.getSortedNumeric(context.reader(), field), selector, type);
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -177,7 +177,7 @@ public class SortedSetSortField extends SortField {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<?> getComparator(int numHits, int sortPos) {
|
public FieldComparator<?> getComparator(int numHits, boolean enableSkipping) {
|
||||||
return new FieldComparator.TermOrdValComparator(
|
return new FieldComparator.TermOrdValComparator(
|
||||||
numHits, getField(), missingValue == STRING_LAST) {
|
numHits, getField(), missingValue == STRING_LAST) {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -159,7 +159,7 @@ public class TopDocs {
|
||||||
reverseMul = new int[sortFields.length];
|
reverseMul = new int[sortFields.length];
|
||||||
for (int compIDX = 0; compIDX < sortFields.length; compIDX++) {
|
for (int compIDX = 0; compIDX < sortFields.length; compIDX++) {
|
||||||
final SortField sortField = sortFields[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;
|
reverseMul[compIDX] = sortField.getReverse() ? -1 : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,10 +35,10 @@ public class DocComparator extends FieldComparator<Integer> {
|
||||||
private boolean hitsThresholdReached;
|
private boolean hitsThresholdReached;
|
||||||
|
|
||||||
/** Creates a new comparator based on document ids for {@code numHits} */
|
/** 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];
|
this.docIDs = new int[numHits];
|
||||||
// skipping functionality is enabled if we are sorting by _doc in asc order as a primary sort
|
// 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
|
@Override
|
||||||
|
|
|
@ -32,8 +32,8 @@ public class DoubleComparator extends NumericComparator<Double> {
|
||||||
protected double bottom;
|
protected double bottom;
|
||||||
|
|
||||||
public DoubleComparator(
|
public DoubleComparator(
|
||||||
int numHits, String field, Double missingValue, boolean reverse, int sortPos) {
|
int numHits, String field, Double missingValue, boolean reverse, boolean enableSkipping) {
|
||||||
super(field, missingValue != null ? missingValue : 0.0, reverse, sortPos, Double.BYTES);
|
super(field, missingValue != null ? missingValue : 0.0, reverse, enableSkipping, Double.BYTES);
|
||||||
values = new double[numHits];
|
values = new double[numHits];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@ public class FloatComparator extends NumericComparator<Float> {
|
||||||
protected float bottom;
|
protected float bottom;
|
||||||
|
|
||||||
public FloatComparator(
|
public FloatComparator(
|
||||||
int numHits, String field, Float missingValue, boolean reverse, int sortPos) {
|
int numHits, String field, Float missingValue, boolean reverse, boolean enableSkipping) {
|
||||||
super(field, missingValue != null ? missingValue : 0.0f, reverse, sortPos, Float.BYTES);
|
super(field, missingValue != null ? missingValue : 0.0f, reverse, enableSkipping, Float.BYTES);
|
||||||
values = new float[numHits];
|
values = new float[numHits];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@ public class IntComparator extends NumericComparator<Integer> {
|
||||||
protected int bottom;
|
protected int bottom;
|
||||||
|
|
||||||
public IntComparator(
|
public IntComparator(
|
||||||
int numHits, String field, Integer missingValue, boolean reverse, int sortPos) {
|
int numHits, String field, Integer missingValue, boolean reverse, boolean enableSkipping) {
|
||||||
super(field, missingValue != null ? missingValue : 0, reverse, sortPos, Integer.BYTES);
|
super(field, missingValue != null ? missingValue : 0, reverse, enableSkipping, Integer.BYTES);
|
||||||
values = new int[numHits];
|
values = new int[numHits];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@ public class LongComparator extends NumericComparator<Long> {
|
||||||
protected long bottom;
|
protected long bottom;
|
||||||
|
|
||||||
public LongComparator(
|
public LongComparator(
|
||||||
int numHits, String field, Long missingValue, boolean reverse, int sortPos) {
|
int numHits, String field, Long missingValue, boolean reverse, boolean enableSkipping) {
|
||||||
super(field, missingValue != null ? missingValue : 0L, reverse, sortPos, Long.BYTES);
|
super(field, missingValue != null ? missingValue : 0L, reverse, enableSkipping, Long.BYTES);
|
||||||
values = new long[numHits];
|
values = new long[numHits];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,12 +55,12 @@ public abstract class NumericComparator<T extends Number> extends FieldComparato
|
||||||
private boolean canSkipDocuments;
|
private boolean canSkipDocuments;
|
||||||
|
|
||||||
protected NumericComparator(
|
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.field = field;
|
||||||
this.missingValue = missingValue;
|
this.missingValue = missingValue;
|
||||||
this.reverse = reverse;
|
this.reverse = reverse;
|
||||||
// skipping functionality is only relevant for primary sort
|
// skipping functionality is only relevant for primary sort
|
||||||
this.canSkipDocuments = (sortPos == 0);
|
this.canSkipDocuments = enableSkipping;
|
||||||
this.bytesCount = bytesCount;
|
this.bytesCount = bytesCount;
|
||||||
this.bytesComparator = ArrayUtil.getUnsignedComparator(bytesCount);
|
this.bytesComparator = ArrayUtil.getUnsignedComparator(bytesCount);
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ public abstract class NumericComparator<T extends Number> extends FieldComparato
|
||||||
|
|
||||||
public NumericLeafComparator(LeafReaderContext context) throws IOException {
|
public NumericLeafComparator(LeafReaderContext context) throws IOException {
|
||||||
this.docValues = getNumericDocValues(context, field);
|
this.docValues = getNumericDocValues(context, field);
|
||||||
this.pointValues = canSkipDocuments ? getPointValues(context, field) : null;
|
this.pointValues = canSkipDocuments ? context.reader().getPointValues(field) : null;
|
||||||
if (pointValues != null) {
|
if (pointValues != null) {
|
||||||
FieldInfo info = context.reader().getFieldInfos().fieldInfo(field);
|
FieldInfo info = context.reader().getFieldInfos().fieldInfo(field);
|
||||||
if (info == null || info.getPointDimensionCount() == 0) {
|
if (info == null || info.getPointDimensionCount() == 0) {
|
||||||
|
@ -138,10 +138,9 @@ public abstract class NumericComparator<T extends Number> extends FieldComparato
|
||||||
/**
|
/**
|
||||||
* Retrieves the NumericDocValues for the field in this segment
|
* Retrieves the NumericDocValues for the field in this segment
|
||||||
*
|
*
|
||||||
* <p>If you override this method, you must also override {@link
|
* <p>If you override this method, you should probably always disable skipping as the comparator
|
||||||
* #getPointValues(LeafReaderContext, String)} This class uses sort optimization that leverages
|
* uses values from the points index to build its competitive iterators, and assumes that the
|
||||||
* points to filter out non-competitive matches, which relies on the assumption that points and
|
* values in doc values and points are the same.
|
||||||
* doc values record the same information.
|
|
||||||
*
|
*
|
||||||
* @param context – reader context
|
* @param context – reader context
|
||||||
* @param field - field name
|
* @param field - field name
|
||||||
|
@ -153,26 +152,6 @@ public abstract class NumericComparator<T extends Number> extends FieldComparato
|
||||||
return DocValues.getNumeric(context.reader(), field);
|
return DocValues.getNumeric(context.reader(), field);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves point values for the field in this segment
|
|
||||||
*
|
|
||||||
* <p>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
|
@Override
|
||||||
public void setBottom(int slot) throws IOException {
|
public void setBottom(int slot) throws IOException {
|
||||||
queueFull = true; // if we are setting bottom, it means that we have collected enough hits
|
queueFull = true; // if we are setting bottom, it means that we have collected enough hits
|
||||||
|
|
|
@ -118,7 +118,7 @@ final class JustCompileSearch {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<?> newComparator(
|
public FieldComparator<?> newComparator(
|
||||||
String fieldname, int numHits, int sortPos, boolean reversed) {
|
String fieldname, int numHits, boolean enableSkipping, boolean reversed) {
|
||||||
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
|
throw new UnsupportedOperationException(UNSUPPORTED_MSG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,7 +151,7 @@ class ElevationComparatorSource extends FieldComparatorSource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<Integer> newComparator(
|
public FieldComparator<Integer> newComparator(
|
||||||
final String fieldname, final int numHits, int sortPos, boolean reversed) {
|
final String fieldname, final int numHits, boolean enableSkipping, boolean reversed) {
|
||||||
return new FieldComparator<Integer>() {
|
return new FieldComparator<Integer>() {
|
||||||
|
|
||||||
private final int[] values = new int[numHits];
|
private final int[] values = new int[numHits];
|
||||||
|
|
|
@ -258,7 +258,7 @@ public abstract class AllGroupHeadsCollector<T> extends SimpleCollector {
|
||||||
comparators = new FieldComparator[sortFields.length];
|
comparators = new FieldComparator[sortFields.length];
|
||||||
leafComparators = new LeafFieldComparator[sortFields.length];
|
leafComparators = new LeafFieldComparator[sortFields.length];
|
||||||
for (int i = 0; i < sortFields.length; i++) {
|
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] = comparators[i].getLeafComparator(context);
|
||||||
leafComparators[i].setScorer(scorer);
|
leafComparators[i].setScorer(scorer);
|
||||||
leafComparators[i].copy(0, doc);
|
leafComparators[i].copy(0, doc);
|
||||||
|
|
|
@ -240,7 +240,7 @@ public class BlockGroupingCollector extends SimpleCollector {
|
||||||
reversed = new int[sortFields.length];
|
reversed = new int[sortFields.length];
|
||||||
for (int i = 0; i < sortFields.length; i++) {
|
for (int i = 0; i < sortFields.length; i++) {
|
||||||
final SortField sortField = sortFields[i];
|
final SortField sortField = sortFields[i];
|
||||||
comparators[i] = sortField.getComparator(topNGroups, i);
|
comparators[i] = sortField.getComparator(topNGroups, false);
|
||||||
reversed[i] = sortField.getReverse() ? -1 : 1;
|
reversed[i] = sortField.getReverse() ? -1 : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class FirstPassGroupingCollector<T> extends SimpleCollector {
|
||||||
|
|
||||||
// use topNGroups + 1 so we have a spare slot to use for comparing (tracked by
|
// use topNGroups + 1 so we have a spare slot to use for comparing (tracked by
|
||||||
// this.spareSlot):
|
// this.spareSlot):
|
||||||
comparators[i] = sortField.getComparator(topNGroups + 1, i);
|
comparators[i] = sortField.getComparator(topNGroups + 1, false);
|
||||||
reversed[i] = sortField.getReverse() ? -1 : 1;
|
reversed[i] = sortField.getReverse() ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,7 @@ public class SearchGroup<T> {
|
||||||
reversed = new int[sortFields.length];
|
reversed = new int[sortFields.length];
|
||||||
for (int compIDX = 0; compIDX < sortFields.length; compIDX++) {
|
for (int compIDX = 0; compIDX < sortFields.length; compIDX++) {
|
||||||
final SortField sortField = sortFields[compIDX];
|
final SortField sortField = sortFields[compIDX];
|
||||||
comparators[compIDX] = sortField.getComparator(1, compIDX);
|
comparators[compIDX] = sortField.getComparator(1, false);
|
||||||
reversed[compIDX] = sortField.getReverse() ? -1 : 1;
|
reversed[compIDX] = sortField.getReverse() ? -1 : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import org.apache.lucene.index.DocValues;
|
||||||
import org.apache.lucene.index.FilterNumericDocValues;
|
import org.apache.lucene.index.FilterNumericDocValues;
|
||||||
import org.apache.lucene.index.LeafReaderContext;
|
import org.apache.lucene.index.LeafReaderContext;
|
||||||
import org.apache.lucene.index.NumericDocValues;
|
import org.apache.lucene.index.NumericDocValues;
|
||||||
import org.apache.lucene.index.PointValues;
|
|
||||||
import org.apache.lucene.index.SortedDocValues;
|
import org.apache.lucene.index.SortedDocValues;
|
||||||
import org.apache.lucene.index.SortedNumericDocValues;
|
import org.apache.lucene.index.SortedNumericDocValues;
|
||||||
import org.apache.lucene.index.SortedSetDocValues;
|
import org.apache.lucene.index.SortedSetDocValues;
|
||||||
|
@ -112,18 +111,18 @@ public class ToParentBlockJoinSortField extends SortField {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<?> getComparator(int numHits, int sortPos) {
|
public FieldComparator<?> getComparator(int numHits, boolean enableSkipping) {
|
||||||
switch (getType()) {
|
switch (getType()) {
|
||||||
case STRING:
|
case STRING:
|
||||||
return getStringComparator(numHits);
|
return getStringComparator(numHits);
|
||||||
case DOUBLE:
|
case DOUBLE:
|
||||||
return getDoubleComparator(numHits, sortPos);
|
return getDoubleComparator(numHits);
|
||||||
case FLOAT:
|
case FLOAT:
|
||||||
return getFloatComparator(numHits, sortPos);
|
return getFloatComparator(numHits);
|
||||||
case LONG:
|
case LONG:
|
||||||
return getLongComparator(numHits, sortPos);
|
return getLongComparator(numHits);
|
||||||
case INT:
|
case INT:
|
||||||
return getIntComparator(numHits, sortPos);
|
return getIntComparator(numHits);
|
||||||
case CUSTOM:
|
case CUSTOM:
|
||||||
case DOC:
|
case DOC:
|
||||||
case REWRITEABLE:
|
case REWRITEABLE:
|
||||||
|
@ -154,8 +153,8 @@ public class ToParentBlockJoinSortField extends SortField {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private FieldComparator<?> getIntComparator(int numHits, int sortPos) {
|
private FieldComparator<?> getIntComparator(int numHits) {
|
||||||
return new IntComparator(numHits, getField(), (Integer) missingValue, getReverse(), sortPos) {
|
return new IntComparator(numHits, getField(), (Integer) missingValue, getReverse(), false) {
|
||||||
@Override
|
@Override
|
||||||
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
|
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
|
||||||
return new IntLeafComparator(context) {
|
return new IntLeafComparator(context) {
|
||||||
|
@ -173,18 +172,13 @@ public class ToParentBlockJoinSortField extends SortField {
|
||||||
}
|
}
|
||||||
return BlockJoinSelector.wrap(sortedNumeric, type, parents, toIter(children));
|
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) {
|
private FieldComparator<?> getLongComparator(int numHits) {
|
||||||
return new LongComparator(numHits, getField(), (Long) missingValue, getReverse(), sortPos) {
|
return new LongComparator(numHits, getField(), (Long) missingValue, getReverse(), false) {
|
||||||
@Override
|
@Override
|
||||||
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
|
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
|
||||||
return new LongLeafComparator(context) {
|
return new LongLeafComparator(context) {
|
||||||
|
@ -202,18 +196,13 @@ public class ToParentBlockJoinSortField extends SortField {
|
||||||
}
|
}
|
||||||
return BlockJoinSelector.wrap(sortedNumeric, type, parents, toIter(children));
|
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) {
|
private FieldComparator<?> getFloatComparator(int numHits) {
|
||||||
return new FloatComparator(numHits, getField(), (Float) missingValue, getReverse(), sortPos) {
|
return new FloatComparator(numHits, getField(), (Float) missingValue, getReverse(), false) {
|
||||||
@Override
|
@Override
|
||||||
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
|
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
|
||||||
return new FloatLeafComparator(context) {
|
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) {
|
private FieldComparator<?> getDoubleComparator(int numHits) {
|
||||||
return new DoubleComparator(
|
return new DoubleComparator(numHits, getField(), (Double) missingValue, getReverse(), false) {
|
||||||
numHits, getField(), (Double) missingValue, getReverse(), sortPost) {
|
|
||||||
@Override
|
@Override
|
||||||
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
|
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
|
||||||
return new DoubleLeafComparator(context) {
|
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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -381,7 +381,7 @@ public abstract class ValueSource {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<Double> newComparator(
|
public FieldComparator<Double> newComparator(
|
||||||
String fieldname, int numHits, int sortPos, boolean reversed) {
|
String fieldname, int numHits, boolean enableSkipping, boolean reversed) {
|
||||||
return new ValueSourceComparator(context, numHits);
|
return new ValueSourceComparator(context, numHits);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,7 +247,8 @@ public class IndexSortSortedNumericDocValuesRangeQuery extends Query {
|
||||||
private static ValueComparator loadComparator(
|
private static ValueComparator loadComparator(
|
||||||
SortField sortField, long topValue, LeafReaderContext context) throws IOException {
|
SortField sortField, long topValue, LeafReaderContext context) throws IOException {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
FieldComparator<Long> fieldComparator = (FieldComparator<Long>) sortField.getComparator(1, 0);
|
FieldComparator<Long> fieldComparator =
|
||||||
|
(FieldComparator<Long>) sortField.getComparator(1, false);
|
||||||
fieldComparator.setTopValue(topValue);
|
fieldComparator.setTopValue(topValue);
|
||||||
|
|
||||||
LeafFieldComparator leafFieldComparator = fieldComparator.getLeafComparator(context);
|
LeafFieldComparator leafFieldComparator = fieldComparator.getLeafComparator(context);
|
||||||
|
|
|
@ -41,7 +41,7 @@ final class Geo3DPointOutsideSortField extends SortField {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<?> getComparator(int numHits, int sortPos) {
|
public FieldComparator<?> getComparator(int numHits, boolean enableSkipping) {
|
||||||
return new Geo3DPointOutsideDistanceComparator(getField(), planetModel, distanceShape, numHits);
|
return new Geo3DPointOutsideDistanceComparator(getField(), planetModel, distanceShape, numHits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ final class Geo3DPointSortField extends SortField {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FieldComparator<?> getComparator(int numHits, int sortPos) {
|
public FieldComparator<?> getComparator(int numHits, boolean enableSkipping) {
|
||||||
return new Geo3DPointDistanceComparator(getField(), planetModel, distanceShape, numHits);
|
return new Geo3DPointDistanceComparator(getField(), planetModel, distanceShape, numHits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue