diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index a22742196ef..d0d3c14d7f8 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -245,6 +245,8 @@ Optimizations * LUCENE-10442: When indexQuery or/and dvQuery be a MatchAllDocsQuery then IndexOrDocValuesQuery should be rewrite to MatchAllDocsQuery. (Lu Xugang) +* LUCENE-10450: IndexSortSortedNumericDocValuesRangeQuery could be rewrite to MatchAllDocsQuery. (Lu Xugang) + Changes in runtime behavior --------------------- 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 a35352564a9..58f27e5f5c9 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 @@ -30,6 +30,7 @@ import org.apache.lucene.search.DocValuesFieldExistsQuery; import org.apache.lucene.search.FieldComparator; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.LeafFieldComparator; +import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.QueryVisitor; import org.apache.lucene.search.ScoreMode; @@ -140,6 +141,9 @@ public class IndexSortSortedNumericDocValuesRangeQuery extends Query { } Query rewrittenFallback = fallbackQuery.rewrite(reader); + if (rewrittenFallback.getClass() == MatchAllDocsQuery.class) { + return new MatchAllDocsQuery(); + } if (rewrittenFallback == fallbackQuery) { return this; } else {