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 4361243..7cc1eac 100644 --- a/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java +++ b/lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java @@ -25,6 +25,7 @@ import java.util.function.LongToDoubleFunction; import org.apache.lucene.index.DocValues; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.NumericDocValues; +import org.apache.lucene.util.Bits; /** * Base class for producing {@link DoubleValues} @@ -194,7 +195,8 @@ public abstract class DoubleValuesSource { @Override public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { final NumericDocValues values = DocValues.getNumeric(ctx.reader(), field); - return toDoubleValues(values, decoder::applyAsDouble); + final Bits matchingBits = DocValues.getDocsWithField(ctx.reader(), field); + return toDoubleValues(values, matchingBits, decoder::applyAsDouble); } @Override @@ -261,7 +263,7 @@ public abstract class DoubleValuesSource { } } - private static DoubleValues toDoubleValues(NumericDocValues in, LongToDoubleFunction map) { + private static DoubleValues toDoubleValues(NumericDocValues in, Bits matchingBits, LongToDoubleFunction map) { return new DoubleValues() { int current = -1; @@ -274,7 +276,7 @@ public abstract class DoubleValuesSource { @Override public boolean advanceExact(int target) throws IOException { current = target; - return true; + return matchingBits.get(target); } }; 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 4165e90..9599f8d 100644 --- a/lucene/core/src/java/org/apache/lucene/search/LongValuesSource.java +++ b/lucene/core/src/java/org/apache/lucene/search/LongValuesSource.java @@ -23,6 +23,7 @@ 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.util.Bits; /** * Base class for producing {@link LongValues} @@ -98,7 +99,8 @@ public abstract class LongValuesSource { @Override public LongValues getValues(LeafReaderContext ctx, DoubleValues scores) throws IOException { final NumericDocValues values = DocValues.getNumeric(ctx.reader(), field); - return toLongValues(values); + final Bits matchingBits = DocValues.getDocsWithField(ctx.reader(), field); + return toLongValues(values, matchingBits); } @Override @@ -165,7 +167,7 @@ public abstract class LongValuesSource { } } - private static LongValues toLongValues(NumericDocValues in) { + private static LongValues toLongValues(NumericDocValues in, Bits matchingBits) { return new LongValues() { int current = -1; @@ -178,7 +180,7 @@ public abstract class LongValuesSource { @Override public boolean advanceExact(int target) throws IOException { current = target; - return true; + return matchingBits.get(target); } };