Skip to content

IndexOrDocValuesQuery and IndexSortSortedNumericDocValuesRangeQuery should only be counted once when computing maxClauseCount #14759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ public Query rewrite(IndexSearcher indexSearcher) throws IOException {
@Override
public void visit(QueryVisitor visitor) {
QueryVisitor v = visitor.getSubVisitor(BooleanClause.Occur.MUST, this);
// we cannot register this query in the visitor, since we don't have the field name,
// so we just visit one of the subqueries.
indexQuery.visit(v);
dvQuery.visit(v);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public int hashCode() {
public void visit(QueryVisitor visitor) {
if (visitor.acceptField(field)) {
visitor.visitLeaf(this);
fallbackQuery.visit(visitor);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@

import java.io.IOException;
import java.util.Arrays;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.LongField;
import org.apache.lucene.document.LongPoint;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.index.RandomIndexWriter;
import org.apache.lucene.tests.util.LuceneTestCase;

public class TestMaxClauseLimit extends LuceneTestCase {
Expand Down Expand Up @@ -158,4 +165,48 @@ public void testMultiExactWithRepeats() throws IOException {
searcher.rewrite(qb.build());
});
}

public void testIndexOrDocValues() throws IOException {
Directory dir = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
Document d = new Document();
d.add(new LongField("foo", 0L, LongField.Store.NO));
writer.addDocument(d);
d = new Document();
d.add(new LongField("foo", Long.MAX_VALUE, LongField.Store.NO));
writer.addDocument(d);

IndexReader reader = writer.getReader();
IndexSearcher searcher = newSearcher(reader);
writer.close();
int maxClauseCount = IndexSearcher.getMaxClauseCount();
BooleanQuery.Builder qb = new BooleanQuery.Builder();

for (int i = 0; i < maxClauseCount; i++) {
qb.add(LongPoint.newRangeQuery("foo", 0, i), BooleanClause.Occur.SHOULD);
}
// should not throw an exception, because it is below the limit
searcher.rewrite(qb.build());

qb = new BooleanQuery.Builder();
for (int i = 0; i < maxClauseCount; i++) {
qb.add(LongField.newRangeQuery("foo", 0, i), BooleanClause.Occur.SHOULD);
}
// should not throw an exception, because it is below the limit
searcher.rewrite(qb.build());

qb = new BooleanQuery.Builder();
for (int i = 0; i < maxClauseCount; i++) {
qb.add(
new IndexOrDocValuesQuery(
LongPoint.newRangeQuery("foo", 0, i),
SortedNumericDocValuesField.newSlowRangeQuery("foo", 0, i)),
BooleanClause.Occur.SHOULD);
}
// should not throw an exception, because it is below the limit
searcher.rewrite(qb.build());

reader.close();
dir.close();
}
}