Skip to content

Commit

Permalink
Fix standard retriever rewrite (elastic#114480)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimczi authored Oct 10, 2024
1 parent 4d6f195 commit 430ec3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
3 changes: 0 additions & 3 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,6 @@ tests:
- class: org.elasticsearch.xpack.inference.InferenceRestIT
method: test {p0=inference/40_semantic_text_query/Query a field that uses the default ELSER 2 endpoint}
issue: https://github.com/elastic/elasticsearch/issues/114376
- class: org.elasticsearch.search.retriever.StandardRetrieverBuilderParsingTests
method: testRewrite
issue: https://github.com/elastic/elasticsearch/issues/114466
- class: org.elasticsearch.search.retriever.RankDocsRetrieverBuilderTests
method: testRewrite
issue: https://github.com/elastic/elasticsearch/issues/114467
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,29 @@ private StandardRetrieverBuilder(StandardRetrieverBuilder clone) {
@Override
public RetrieverBuilder rewrite(QueryRewriteContext ctx) throws IOException {
boolean changed = false;
List<SortBuilder<?>> newSortBuilders = null;
List<SortBuilder<?>> rewrittenSortBuilders = null;
if (sortBuilders != null) {
newSortBuilders = new ArrayList<>(sortBuilders.size());
rewrittenSortBuilders = new ArrayList<>(sortBuilders.size());
for (var sort : sortBuilders) {
var newSort = sort.rewrite(ctx);
newSortBuilders.add(newSort);
changed = newSort != sort;
rewrittenSortBuilders.add(newSort);
changed |= newSort != sort;
}
}
var rewrittenFilters = rewritePreFilters(ctx);
changed |= rewrittenFilters != preFilterQueryBuilders;

QueryBuilder queryBuilderRewrite = null;
QueryBuilder rewrittenQuery = null;
if (queryBuilder != null) {
queryBuilderRewrite = queryBuilder.rewrite(ctx);
changed |= queryBuilderRewrite != queryBuilder;
rewrittenQuery = queryBuilder.rewrite(ctx);
changed |= rewrittenQuery != queryBuilder;
}

if (changed) {
var rewritten = new StandardRetrieverBuilder(this);
rewritten.sortBuilders = newSortBuilders;
rewritten.preFilterQueryBuilders = preFilterQueryBuilders;
rewritten.queryBuilder = queryBuilderRewrite;
rewritten.sortBuilders = rewrittenSortBuilders;
rewritten.preFilterQueryBuilders = rewrittenFilters;
rewritten.queryBuilder = rewrittenQuery;
return rewritten;
}
return this;
Expand Down

0 comments on commit 430ec3b

Please sign in to comment.