Skip to content

Commit

Permalink
Fix the visit of inner query for NestedQueryBuilder (#14968)
Browse files Browse the repository at this point in the history
Signed-off-by: zhichao-aws <[email protected]>
  • Loading branch information
zhichao-aws authored Jul 25, 2024
1 parent d09642c commit b21c13e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.ReaderUtil;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.MultiCollector;
import org.apache.lucene.search.Query;
Expand Down Expand Up @@ -505,4 +506,12 @@ public TopDocsAndMaxScore topDocs(SearchHit hit) throws IOException {
}
}
}

@Override
public void visit(QueryBuilderVisitor visitor) {
visitor.accept(this);
if (query != null) {
visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(query);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@
import org.hamcrest.Matchers;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand Down Expand Up @@ -565,4 +567,13 @@ void doWithDepth(int depth, ThrowingConsumer<QueryShardContext> test) throws Exc
);
}
}

public void testVisit() {
NestedQueryBuilder builder = new NestedQueryBuilder("path", new MatchAllQueryBuilder(), ScoreMode.None);

List<QueryBuilder> visitedQueries = new ArrayList<>();
builder.visit(createTestVisitor(visitedQueries));

assertEquals(2, visitedQueries.size());
}
}

0 comments on commit b21c13e

Please sign in to comment.