mirror of https://github.com/apache/lucene.git
Assert IdxOrDvQuery subqueries and document useful fields (#12442)
This commit is contained in:
parent
59c56a0aed
commit
34721f9439
|
@ -42,6 +42,12 @@ import org.apache.lucene.index.LeafReaderContext;
|
|||
* otherwise, ie. in the case that another part of the query is already leading iteration but we
|
||||
* still need the ability to verify that some documents match.
|
||||
*
|
||||
* <p>Some field types that work well with {@link IndexOrDocValuesQuery} are {@link
|
||||
* org.apache.lucene.document.IntField}, {@link org.apache.lucene.document.LongField}, {@link
|
||||
* org.apache.lucene.document.FloatField}, {@link org.apache.lucene.document.DoubleField}, and
|
||||
* {@link org.apache.lucene.document.KeywordField}. These fields provide both an indexed structure
|
||||
* and doc values.
|
||||
*
|
||||
* <p><b>NOTE</b>This query currently only works well with point range/exact queries and their
|
||||
* equivalent doc values queries.
|
||||
*
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.apache.lucene.index.LeafReaderContext;
|
|||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.BooleanClause.Occur;
|
||||
import org.apache.lucene.store.Directory;
|
||||
import org.apache.lucene.tests.search.QueryUtils;
|
||||
import org.apache.lucene.tests.util.LuceneTestCase;
|
||||
import org.apache.lucene.tests.util.TestUtil;
|
||||
|
||||
|
@ -76,6 +77,7 @@ public class TestIndexOrDocValuesQuery extends LuceneTestCase {
|
|||
NumericDocValuesField.newSlowRangeQuery("f2", 2L, 2L)),
|
||||
Occur.MUST)
|
||||
.build();
|
||||
QueryUtils.check(random(), q1, searcher);
|
||||
|
||||
final Weight w1 = searcher.createWeight(searcher.rewrite(q1), ScoreMode.COMPLETE, 1);
|
||||
final Scorer s1 = w1.scorer(searcher.getIndexReader().leaves().get(0));
|
||||
|
@ -91,6 +93,7 @@ public class TestIndexOrDocValuesQuery extends LuceneTestCase {
|
|||
NumericDocValuesField.newSlowRangeQuery("f2", 42L, 42L)),
|
||||
Occur.MUST)
|
||||
.build();
|
||||
QueryUtils.check(random(), q2, searcher);
|
||||
|
||||
final Weight w2 = searcher.createWeight(searcher.rewrite(q2), ScoreMode.COMPLETE, 1);
|
||||
final Scorer s2 = w2.scorer(searcher.getIndexReader().leaves().get(0));
|
||||
|
@ -142,6 +145,7 @@ public class TestIndexOrDocValuesQuery extends LuceneTestCase {
|
|||
SortedNumericDocValuesField.newSlowRangeQuery("f2", 2L, 2L)),
|
||||
Occur.MUST)
|
||||
.build();
|
||||
QueryUtils.check(random(), q1, searcher);
|
||||
|
||||
final Weight w1 = searcher.createWeight(searcher.rewrite(q1), ScoreMode.COMPLETE, 1);
|
||||
final Scorer s1 = w1.scorer(searcher.getIndexReader().leaves().get(0));
|
||||
|
@ -157,6 +161,7 @@ public class TestIndexOrDocValuesQuery extends LuceneTestCase {
|
|||
SortedNumericDocValuesField.newSlowRangeQuery("f2", 42, 42L)),
|
||||
Occur.MUST)
|
||||
.build();
|
||||
QueryUtils.check(random(), q2, searcher);
|
||||
|
||||
final Weight w2 = searcher.createWeight(searcher.rewrite(q2), ScoreMode.COMPLETE, 1);
|
||||
final Scorer s2 = w2.scorer(searcher.getIndexReader().leaves().get(0));
|
||||
|
@ -172,6 +177,7 @@ public class TestIndexOrDocValuesQuery extends LuceneTestCase {
|
|||
SortedNumericDocValuesField.newSlowRangeQuery("f2", 42, 42L)),
|
||||
Occur.MUST)
|
||||
.build();
|
||||
QueryUtils.check(random(), q3, searcher);
|
||||
|
||||
final Weight w3 = searcher.createWeight(searcher.rewrite(q3), ScoreMode.COMPLETE, 1);
|
||||
final Scorer s3 = w3.scorer(searcher.getIndexReader().leaves().get(0));
|
||||
|
@ -206,6 +212,7 @@ public class TestIndexOrDocValuesQuery extends LuceneTestCase {
|
|||
new IndexOrDocValuesQuery(
|
||||
LongPoint.newExactQuery("f2", 42),
|
||||
SortedNumericDocValuesField.newSlowRangeQuery("f2", 42, 42L));
|
||||
QueryUtils.check(random(), query, searcher);
|
||||
|
||||
final int searchCount = searcher.count(query);
|
||||
final Weight weight = searcher.createWeight(query, ScoreMode.COMPLETE, 1);
|
||||
|
|
|
@ -50,6 +50,7 @@ import org.apache.lucene.search.QueryVisitor;
|
|||
import org.apache.lucene.search.Scorable;
|
||||
import org.apache.lucene.search.ScoreMode;
|
||||
import org.apache.lucene.search.Scorer;
|
||||
import org.apache.lucene.search.ScorerSupplier;
|
||||
import org.apache.lucene.search.SimpleCollector;
|
||||
import org.apache.lucene.search.TopDocs;
|
||||
import org.apache.lucene.search.Weight;
|
||||
|
@ -675,7 +676,15 @@ public class QueryUtils {
|
|||
query = searcher.rewrite(query);
|
||||
Weight weight = searcher.createWeight(query, ScoreMode.COMPLETE, 1);
|
||||
for (LeafReaderContext context : searcher.getIndexReader().leaves()) {
|
||||
final Scorer scorer = weight.scorer(context);
|
||||
final Scorer scorer;
|
||||
final ScorerSupplier scorerSupplier = weight.scorerSupplier(context);
|
||||
if (scorerSupplier == null) {
|
||||
scorer = null;
|
||||
} else {
|
||||
// For IndexOrDocValuesQuey, the bulk scorer will use the indexed structure query
|
||||
// and the scorer with a lead cost of 0 will use the doc values query.
|
||||
scorer = scorerSupplier.get(0);
|
||||
}
|
||||
final BulkScorer bulkScorer = weight.bulkScorer(context);
|
||||
if (scorer == null && bulkScorer == null) {
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue