From cb50642494fdf1bfab6503765b891b3d30dc36f7 Mon Sep 17 00:00:00 2001 From: Tommaso Teofili Date: Fri, 18 Jul 2025 12:09:15 +0200 Subject: [PATCH] ScoreTests capability check --- .../_snippets/functions/parameters/score.md | 2 +- .../kibana/definition/functions/score.json | 2 +- .../function/fulltext/ScoreTests.java | 23 ++++++------------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/docs/reference/query-languages/esql/_snippets/functions/parameters/score.md b/docs/reference/query-languages/esql/_snippets/functions/parameters/score.md index 511ced1094f91..59fdd3c54e1dd 100644 --- a/docs/reference/query-languages/esql/_snippets/functions/parameters/score.md +++ b/docs/reference/query-languages/esql/_snippets/functions/parameters/score.md @@ -3,5 +3,5 @@ **Parameters** `query` -: (combinations of) full text function(s). +: Boolean expression that contains full text function(s) to be scored. diff --git a/docs/reference/query-languages/esql/kibana/definition/functions/score.json b/docs/reference/query-languages/esql/kibana/definition/functions/score.json index c9b5e22a02e4c..4772093e349d9 100644 --- a/docs/reference/query-languages/esql/kibana/definition/functions/score.json +++ b/docs/reference/query-languages/esql/kibana/definition/functions/score.json @@ -10,7 +10,7 @@ "name" : "query", "type" : "boolean", "optional" : false, - "description" : "(combinations of) full text function(s)." + "description" : "Boolean expression that contains full text function(s) to be scored." } ], "variadic" : false, diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/fulltext/ScoreTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/fulltext/ScoreTests.java index 346b1cafa02f4..74b2dffe2e4c4 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/fulltext/ScoreTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/fulltext/ScoreTests.java @@ -10,17 +10,17 @@ import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; +import org.elasticsearch.xpack.esql.action.EsqlCapabilities; import org.elasticsearch.xpack.esql.core.expression.Expression; import org.elasticsearch.xpack.esql.core.tree.Source; import org.elasticsearch.xpack.esql.expression.function.FunctionName; import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier; -import org.elasticsearch.xpack.esql.io.stream.PlanStreamOutput; +import org.junit.BeforeClass; import java.util.ArrayList; import java.util.List; import java.util.function.Supplier; -import static org.elasticsearch.xpack.esql.SerializationTestUtils.serializeDeserialize; import static org.elasticsearch.xpack.esql.core.type.DataType.BOOLEAN; import static org.elasticsearch.xpack.esql.core.type.DataType.DOUBLE; import static org.hamcrest.Matchers.equalTo; @@ -28,6 +28,11 @@ @FunctionName("score") public class ScoreTests extends AbstractMatchFullTextFunctionTests { + @BeforeClass + public static void init() { + assumeTrue("can run this only when score() function is enabled", EsqlCapabilities.Cap.SCORE_FUNCTION.isEnabled()); + } + public ScoreTests(@Name("TestCase") Supplier testCaseSupplier) { this.testCase = testCaseSupplier.get(); } @@ -55,18 +60,4 @@ protected Expression build(Source source, List args) { return new Score(source, args.getFirst()); } - /** - * Copy of the overridden method that doesn't check for children size, as the {@code options} child isn't serialized in Match. - */ - @Override - protected Expression serializeDeserializeExpression(Expression expression) { - Expression newExpression = serializeDeserialize( - expression, - PlanStreamOutput::writeNamedWriteable, - in -> in.readNamedWriteable(Expression.class), - testCase.getConfiguration() // The configuration query should be == to the source text of the function for this to work - ); - // Fields use synthetic sources, which can't be serialized. So we use the originals instead. - return newExpression.replaceChildren(expression.children()); - } }