From b46dce1dd4d1185efbb5a78f48c039bac72ae29e Mon Sep 17 00:00:00 2001 From: jdnvn Date: Sun, 25 Aug 2024 15:27:01 -0400 Subject: [PATCH 1/3] add visitor logic to FunctionScoreQueryBuilder Signed-off-by: jdnvn --- .../functionscore/FunctionScoreQueryBuilder.java | 10 ++++++++++ .../functionscore/FunctionScoreQueryBuilderTests.java | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/server/src/main/java/org/opensearch/index/query/functionscore/FunctionScoreQueryBuilder.java b/server/src/main/java/org/opensearch/index/query/functionscore/FunctionScoreQueryBuilder.java index b3c797f11de6d..79ff7da1a36ba 100644 --- a/server/src/main/java/org/opensearch/index/query/functionscore/FunctionScoreQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/query/functionscore/FunctionScoreQueryBuilder.java @@ -32,6 +32,7 @@ package org.opensearch.index.query.functionscore; +import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import org.opensearch.common.Nullable; @@ -52,6 +53,7 @@ import org.opensearch.index.query.MatchAllQueryBuilder; import org.opensearch.index.query.MatchNoneQueryBuilder; import org.opensearch.index.query.QueryBuilder; +import org.opensearch.index.query.QueryBuilderVisitor; import org.opensearch.index.query.QueryRewriteContext; import org.opensearch.index.query.QueryShardContext; @@ -704,4 +706,12 @@ private static String parseFiltersAndFunctions( } return currentFieldName; } + + @Override + public void visit(QueryBuilderVisitor visitor) { + visitor.accept(this); + if (query != null) { + visitor.getChildVisitor(BooleanClause.Occur.MUST).accept(query); + } + } } diff --git a/server/src/test/java/org/opensearch/index/query/functionscore/FunctionScoreQueryBuilderTests.java b/server/src/test/java/org/opensearch/index/query/functionscore/FunctionScoreQueryBuilderTests.java index 4e64a1ec03688..78f4163d96d33 100644 --- a/server/src/test/java/org/opensearch/index/query/functionscore/FunctionScoreQueryBuilderTests.java +++ b/server/src/test/java/org/opensearch/index/query/functionscore/FunctionScoreQueryBuilderTests.java @@ -75,6 +75,7 @@ import org.hamcrest.Matcher; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -938,4 +939,14 @@ public void testMustRewrite() throws IOException { e = expectThrows(IllegalStateException.class, () -> functionQueryBuilder2.toQuery(context)); assertEquals("Rewrite first", e.getMessage()); } + + public void testVisit() { + TermQueryBuilder termQueryBuilder = new TermQueryBuilder("unmapped_field", "foo"); + FunctionScoreQueryBuilder builder = new FunctionScoreQueryBuilder(termQueryBuilder); + + List visitedQueries = new ArrayList<>(); + builder.visit(createTestVisitor(visitedQueries)); + + assertEquals(2, visitedQueries.size()); + } } From 4bf593805f0a5452612f31fb9d80ad7cc1fdbfb9 Mon Sep 17 00:00:00 2001 From: jdnvn Date: Sun, 25 Aug 2024 15:44:50 -0400 Subject: [PATCH 2/3] update changelog Signed-off-by: jdnvn --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 720fd7fc9ac1e..11805fb7fb055 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -129,6 +129,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fix AutoDateHistogramAggregator rounding assertion failure ([#17023](https://github.com/opensearch-project/OpenSearch/pull/17023)) - Add highlighting for wildcard search on `match_only_text` field ([#17101](https://github.com/opensearch-project/OpenSearch/pull/17101)) - Fix the failing CI's with `Failed to load eclipse jdt formatter` error ([#17172](https://github.com/opensearch-project/OpenSearch/pull/17172)) +- Fix visit of inner query for FunctionScoreQueryBuilder ([#15404](https://github.com/opensearch-project/OpenSearch/pull/15404)) ### Security From 571931888cb7e9f4f5019da2dcef2b6f98cd1973 Mon Sep 17 00:00:00 2001 From: Joe Donovan Date: Wed, 12 Feb 2025 22:35:59 -0500 Subject: [PATCH 3/3] fix merge issue Signed-off-by: Joe Donovan --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09cde2778fdea..3312d04163d72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fix case insensitive and escaped query on wildcard ([#16827](https://github.com/opensearch-project/OpenSearch/pull/16827)) - Fix exists queries on nested flat_object fields throws exception ([#16803](https://github.com/opensearch-project/OpenSearch/pull/16803)) - Add highlighting for wildcard search on `match_only_text` field ([#17101](https://github.com/opensearch-project/OpenSearch/pull/17101)) -- Fix the failing CI's with `Failed to load eclipse jdt formatter` error ([#17172](https://github.com/opensearch-project/OpenSearch/pull/17172)) - Fix visit of inner query for FunctionScoreQueryBuilder ([#15404](https://github.com/opensearch-project/OpenSearch/pull/15404)) ### Security