Skip to content

Commit

Permalink
Refactor QueryBuilderResolver Rewrite Logic (#119740) (#119834)
Browse files Browse the repository at this point in the history
* Refactor QueryBuilderResolver Rewrite Logic

This commit improves the rewrite logic by switching to reference comparison for termination checks.
While the existing implementation functions correctly, the rewrite contract is designed to compare references rather than performing a full object comparison, which is unnecessary.

Additionally, this change guarantees that only a single rewrite pass is executed per query builder.

* avoid getting the value

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Felix Barnsteiner <felixbarny@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 9, 2025
1 parent 27d4bfe commit c505da9
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,12 @@ public FullTextFunctionsRewritable rewrite(QueryRewriteContext ctx) throws IOExc
Map<FullTextFunction, QueryBuilder> results = new HashMap<>();

boolean hasChanged = false;
for (FullTextFunction func : queryBuilderMap.keySet()) {
var initial = queryBuilderMap.get(func);
var rewritten = Rewriteable.rewrite(initial, ctx, false);
for (var entry : queryBuilderMap.entrySet()) {
var initial = entry.getValue();
var rewritten = initial.rewrite(ctx);
hasChanged |= rewritten != initial;

if (rewritten.equals(initial) == false) {
hasChanged = true;
}

results.put(func, rewritten);
results.put(entry.getKey(), rewritten);
}

return hasChanged ? new FullTextFunctionsRewritable(results) : this;
Expand Down

0 comments on commit c505da9

Please sign in to comment.