Skip to content

Commit

Permalink
Add NestedField Visit
Browse files Browse the repository at this point in the history
Signed-off-by: luyuncheng <[email protected]>
  • Loading branch information
luyuncheng committed Jun 4, 2024
1 parent 581fcd2 commit e72e9b3
Show file tree
Hide file tree
Showing 2 changed files with 24 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 @@ -371,6 +372,14 @@ public void extractInnerHitBuilders(Map<String, InnerHitContextBuilder> innerHit
}
}

@Override
public void visit(QueryBuilderVisitor visitor) {
visitor.accept(this);
if (query != null) {
query.visit(visitor.getChildVisitor(BooleanClause.Occur.MUST));
}
}

/**
* Context builder for nested inner hits
*
Expand Down
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 @@ -540,6 +542,19 @@ public void testUpdateMaxDepthSettings() throws Exception {
});
}

public void testVisit() {
NestedQueryBuilder queryBuilder = new NestedQueryBuilder(
"nested1",
new BoolQueryBuilder().must(new TermQueryBuilder("must_field1", "value1"))
.filter(new TermQueryBuilder("must_field2", "value2")),
ScoreMode.None
);
List<QueryBuilder> visitorQueries = new ArrayList<>();
queryBuilder.visit(createTestVisitor(visitorQueries));

assertEquals(4, visitorQueries.size());
}

void doWithDepth(int depth, ThrowingConsumer<QueryShardContext> test) throws Exception {
QueryShardContext context = createShardContext();
int defLimit = context.getIndexSettings().getMaxNestedQueryDepth();
Expand Down

0 comments on commit e72e9b3

Please sign in to comment.