mirror of https://github.com/apache/lucene.git
LUCENE-10435: Break loop early while checking whether DocValuesFieldExistsQuery can be rewrite to MatchAllDocsQuery (#701)
This commit is contained in:
parent
ab47db4fee
commit
43e89d6a29
|
@ -69,17 +69,18 @@ public final class DocValuesFieldExistsQuery extends Query {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Query rewrite(IndexReader reader) throws IOException {
|
public Query rewrite(IndexReader reader) throws IOException {
|
||||||
int rewritableReaders = 0;
|
boolean allReadersRewritable = true;
|
||||||
for (LeafReaderContext context : reader.leaves()) {
|
for (LeafReaderContext context : reader.leaves()) {
|
||||||
LeafReader leaf = context.reader();
|
LeafReader leaf = context.reader();
|
||||||
Terms terms = leaf.terms(field);
|
Terms terms = leaf.terms(field);
|
||||||
PointValues pointValues = leaf.getPointValues(field);
|
PointValues pointValues = leaf.getPointValues(field);
|
||||||
if ((terms != null && terms.getDocCount() == leaf.maxDoc())
|
if ((terms == null || terms.getDocCount() != leaf.maxDoc())
|
||||||
|| (pointValues != null && pointValues.getDocCount() == leaf.maxDoc())) {
|
&& (pointValues == null || pointValues.getDocCount() != leaf.maxDoc())) {
|
||||||
rewritableReaders++;
|
allReadersRewritable = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rewritableReaders == reader.leaves().size()) {
|
if (allReadersRewritable) {
|
||||||
return new MatchAllDocsQuery();
|
return new MatchAllDocsQuery();
|
||||||
}
|
}
|
||||||
return super.rewrite(reader);
|
return super.rewrite(reader);
|
||||||
|
|
Loading…
Reference in New Issue