Browse Source

ScoreTests capability check (#131516)

Tommaso Teofili 2 months ago
parent
commit
d70093b3ad

+ 1 - 1
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.
 

+ 1 - 1
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,

+ 7 - 16
x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/fulltext/ScoreTests.java

@@ -10,17 +10,17 @@ package org.elasticsearch.xpack.esql.expression.function.fulltext;
 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 @@ import static org.hamcrest.Matchers.equalTo;
 @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.TestCase> testCaseSupplier) {
         this.testCase = testCaseSupplier.get();
     }
@@ -55,18 +60,4 @@ public class ScoreTests extends AbstractMatchFullTextFunctionTests {
         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());
-    }
 }