Skip to content

Commit

Permalink
Update to honor enableSkipping in XFieldComparatorSource
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Handalian <[email protected]>
  • Loading branch information
mch2 committed Dec 4, 2023
1 parent 26f9fc6 commit 2c9ce79
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ abstract class XFieldComparatorSource extends FieldComparatorSource {
protected final MultiValueMode sortMode;
protected final Object missingValue;
protected final Nested nested;
protected Pruning pruning;
protected boolean enableSkipping;

public XFieldComparatorSource(Object missingValue, MultiValueMode sortMode, Nested nested) {
this.sortMode = sortMode;
this.missingValue = missingValue;
this.nested = nested;
this.pruning = Pruning.GREATER_THAN; // true by default
this.enableSkipping = true; // true by default
}

public MultiValueMode sortMode() {
Expand All @@ -139,7 +139,14 @@ public Nested nested() {
}

public void disableSkipping() {
this.pruning = Pruning.NONE;
this.enableSkipping = false;
}

protected Pruning filterPruning(Pruning pruning) {
if (this.enableSkipping) {
return pruning;
}
return Pruning.NONE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public FieldComparator<?> newComparator(String fieldname, int numHits, Pruning p
indexFieldData.getFieldName(),
sortMissingLast,
reversed,
pruning
filterPruning(pruning)
) {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public FieldComparator<?> newComparator(String fieldname, int numHits, Pruning p
assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldName());

final double dMissingValue = (Double) missingObject(missingValue, reversed);
return new DoubleComparator(numHits, fieldname, dMissingValue, reversed, pruning) {
return new DoubleComparator(numHits, fieldname, dMissingValue, reversed, filterPruning(pruning)) {
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
return new DoubleLeafComparator(context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public FieldComparator<?> newComparator(String fieldname, int numHits, Pruning p
assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldName());

final float fMissingValue = (Float) missingObject(missingValue, reversed);
return new FloatComparator(numHits, fieldname, fMissingValue, reversed, pruning) {
return new FloatComparator(numHits, fieldname, fMissingValue, reversed, filterPruning(pruning)) {
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
return new FloatLeafComparator(context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public FieldComparator<?> newComparator(String fieldname, int numHits, Pruning p
assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldName());

final float fMissingValue = (Float) missingObject(missingValue, reversed);
return new HalfFloatComparator(numHits, fieldname, fMissingValue, reversed, pruning) {
return new HalfFloatComparator(numHits, fieldname, fMissingValue, reversed, filterPruning(pruning)) {
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
return new HalfFloatLeafComparator(context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public FieldComparator<?> newComparator(String fieldname, int numHits, Pruning p
assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldName());

final int iMissingValue = (Integer) missingObject(missingValue, reversed);
return new IntComparator(numHits, fieldname, iMissingValue, reversed, pruning) {
return new IntComparator(numHits, fieldname, iMissingValue, reversed, filterPruning(pruning)) {
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
return new IntLeafComparator(context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public FieldComparator<?> newComparator(String fieldname, int numHits, Pruning p
assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldName());

final long lMissingValue = (Long) missingObject(missingValue, reversed);
return new LongComparator(numHits, fieldname, lMissingValue, reversed, pruning) {
return new LongComparator(numHits, fieldname, lMissingValue, reversed, filterPruning(pruning)) {
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
return new LongLeafComparator(context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public FieldComparator<?> newComparator(String fieldname, int numHits, Pruning p
assert indexFieldData == null || fieldname.equals(indexFieldData.getFieldName());

final BigInteger ulMissingValue = (BigInteger) missingObject(missingValue, reversed);
return new UnsignedLongComparator(numHits, fieldname, ulMissingValue, reversed, pruning) {
return new UnsignedLongComparator(numHits, fieldname, ulMissingValue, reversed, filterPruning(pruning)) {
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
return new UnsignedLongLeafComparator(context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,23 @@
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.index.SortedNumericDocValues;
import org.apache.lucene.index.SortedSetDocValues;
import org.apache.lucene.search.*;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.CollectionTerminatedException;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.FieldComparator;
import org.apache.lucene.search.FieldDoc;
import org.apache.lucene.search.LeafFieldComparator;
import org.apache.lucene.search.Pruning;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreMode;
import org.apache.lucene.search.Scorer;
import org.apache.lucene.search.Sort;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.SortedNumericSelector;
import org.apache.lucene.search.SortedNumericSortField;
import org.apache.lucene.search.Weight;
import org.apache.lucene.search.comparators.LongComparator;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.RoaringDocIdSet;
Expand Down Expand Up @@ -340,7 +356,7 @@ public int hashCode() {

@Override
public FieldComparator<?> getComparator(int numHits, Pruning pruning) {
return new LongComparator(1, delegate.getField(), (Long) missingValue, delegate.getReverse(), pruning) {
return new LongComparator(1, delegate.getField(), (Long) missingValue, delegate.getReverse(), Pruning.NONE) {
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
return new LongLeafComparator(context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ private NumericDoubleValues getNumericDoubleValues(LeafReaderContext context) th

@Override
public FieldComparator<?> newComparator(String fieldname, int numHits, Pruning pruning, boolean reversed) {
return new DoubleComparator(numHits, null, null, reversed, pruning) {
return new DoubleComparator(numHits, null, null, reversed, filterPruning(pruning)) {
@Override
public LeafFieldComparator getLeafComparator(LeafReaderContext context) throws IOException {
return new DoubleLeafComparator(context) {
Expand Down

0 comments on commit 2c9ce79

Please sign in to comment.