|
16 | 16 | import org.apache.lucene.document.LongPoint; |
17 | 17 | import org.apache.lucene.document.SortedNumericDocValuesField; |
18 | 18 | import org.apache.lucene.document.StoredField; |
| 19 | +import org.apache.lucene.index.DocValuesSkipper; |
19 | 20 | import org.apache.lucene.index.IndexReader; |
20 | 21 | import org.apache.lucene.index.LeafReaderContext; |
21 | 22 | import org.apache.lucene.index.PointValues; |
|
69 | 70 | import java.time.ZoneOffset; |
70 | 71 | import java.time.ZonedDateTime; |
71 | 72 | import java.util.Collections; |
| 73 | +import java.util.List; |
72 | 74 | import java.util.Locale; |
73 | 75 | import java.util.Map; |
74 | 76 | import java.util.Objects; |
@@ -827,8 +829,24 @@ public Relation isFieldWithinQuery( |
827 | 829 | QueryRewriteContext context |
828 | 830 | ) throws IOException { |
829 | 831 | if (isIndexed() == false && pointsMetadataAvailable == false && hasDocValues()) { |
830 | | - // we don't have a quick way to run this check on doc values, so fall back to default assuming we are within bounds |
831 | | - return Relation.INTERSECTS; |
| 832 | + if (hasDocValuesSkipper() == false) { |
| 833 | + // we don't have a quick way to run this check on doc values, so fall back to default assuming we are within bounds |
| 834 | + return Relation.INTERSECTS; |
| 835 | + } |
| 836 | + long minValue = Long.MAX_VALUE; |
| 837 | + long maxValue = Long.MIN_VALUE; |
| 838 | + List<LeafReaderContext> leaves = reader.leaves(); |
| 839 | + if (leaves.size() == 0) { |
| 840 | + // no data, so nothing matches |
| 841 | + return Relation.DISJOINT; |
| 842 | + } |
| 843 | + for (LeafReaderContext ctx : leaves) { |
| 844 | + DocValuesSkipper skipper = ctx.reader().getDocValuesSkipper(name()); |
| 845 | + assert skipper != null : "no skipper for field:" + name() + " and reader:" + reader; |
| 846 | + minValue = Long.min(minValue, skipper.minValue()); |
| 847 | + maxValue = Long.max(maxValue, skipper.maxValue()); |
| 848 | + } |
| 849 | + return isFieldWithinQuery(minValue, maxValue, from, to, includeLower, includeUpper, timeZone, dateParser, context); |
832 | 850 | } |
833 | 851 | byte[] minPackedValue = PointValues.getMinPackedValue(reader, name()); |
834 | 852 | if (minPackedValue == null) { |
|
0 commit comments