mirror of https://github.com/apache/lucene.git
Rewrite newSlowRangeQuery to MatchNoDocsQuery when upper > lower (#13425)
This commit is contained in:
parent
801b822972
commit
e868b82045
|
@ -252,6 +252,9 @@ Optimizations
|
|||
|
||||
* GITHUB#13439: Avoid unnecessary memory allocation in PackedLongValues#Iterator. (Zhang Chao)
|
||||
|
||||
* GITHUB##13425: Rewrite SortedNumericDocValuesRangeQuery to MatchNoDocsQuery when the upper bound is smaller than the
|
||||
lower bound. (Ioana Tagirta)
|
||||
|
||||
Bug Fixes
|
||||
---------------------
|
||||
(No changes)
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.lucene.search.ConstantScoreScorer;
|
|||
import org.apache.lucene.search.ConstantScoreWeight;
|
||||
import org.apache.lucene.search.FieldExistsQuery;
|
||||
import org.apache.lucene.search.IndexSearcher;
|
||||
import org.apache.lucene.search.MatchNoDocsQuery;
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.apache.lucene.search.QueryVisitor;
|
||||
import org.apache.lucene.search.ScoreMode;
|
||||
|
@ -87,6 +88,9 @@ final class SortedNumericDocValuesRangeQuery extends Query {
|
|||
if (lowerValue == Long.MIN_VALUE && upperValue == Long.MAX_VALUE) {
|
||||
return new FieldExistsQuery(field);
|
||||
}
|
||||
if (lowerValue > upperValue) {
|
||||
return new MatchNoDocsQuery();
|
||||
}
|
||||
return super.rewrite(indexSearcher);
|
||||
}
|
||||
|
||||
|
|
|
@ -288,6 +288,24 @@ public class TestDocValuesQueries extends LuceneTestCase {
|
|||
dir.close();
|
||||
}
|
||||
|
||||
public void testSlowRangeQueryRewrite() throws IOException {
|
||||
Directory dir = newDirectory();
|
||||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
|
||||
IndexReader reader = iw.getReader();
|
||||
iw.close();
|
||||
IndexSearcher searcher = newSearcher(reader);
|
||||
|
||||
QueryUtils.checkEqual(
|
||||
NumericDocValuesField.newSlowRangeQuery("foo", 10, 1).rewrite(searcher),
|
||||
new MatchNoDocsQuery());
|
||||
QueryUtils.checkEqual(
|
||||
NumericDocValuesField.newSlowRangeQuery("foo", Long.MIN_VALUE, Long.MAX_VALUE)
|
||||
.rewrite(searcher),
|
||||
new FieldExistsQuery("foo"));
|
||||
reader.close();
|
||||
dir.close();
|
||||
}
|
||||
|
||||
public void testSortedNumericNPE() throws IOException {
|
||||
Directory dir = newDirectory();
|
||||
RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
|
||||
|
|
Loading…
Reference in New Issue