Skip to content

Commit 4d32942

Browse files
committed
Add tests
1 parent 4aecaea commit 4d32942

File tree

1 file changed

+58
-13
lines changed
  • x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin

1 file changed

+58
-13
lines changed

x-pack/plugin/esql/src/internalClusterTest/java/org/elasticsearch/xpack/esql/plugin/MatchFunctionIT.java

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.elasticsearch.action.index.IndexRequest;
1212
import org.elasticsearch.action.support.WriteRequest;
1313
import org.elasticsearch.common.settings.Settings;
14+
import org.elasticsearch.xpack.esql.EsqlTestUtils;
1415
import org.elasticsearch.xpack.esql.VerificationException;
1516
import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase;
1617
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
@@ -20,6 +21,9 @@
2021

2122
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
2223
import static org.hamcrest.CoreMatchers.containsString;
24+
import static org.hamcrest.Matchers.equalTo;
25+
import static org.hamcrest.Matchers.greaterThan;
26+
import static org.hamcrest.Matchers.lessThan;
2327

2428
//@TestLogging(value = "org.elasticsearch.xpack.esql:TRACE,org.elasticsearch.compute:TRACE", reason = "debug")
2529
public class MatchFunctionIT extends AbstractEsqlIntegTestCase {
@@ -29,19 +33,6 @@ public void setupIndex() {
2933
createAndPopulateIndex();
3034
}
3135

32-
public void testDELETEME() {
33-
var query = """
34-
FROM test METADATA _score
35-
| WHERE match(content, "fox") OR length(content) < 20
36-
""";
37-
38-
try (var resp = run(query)) {
39-
assertColumnNames(resp.columns(), List.of("id"));
40-
assertColumnTypes(resp.columns(), List.of("integer"));
41-
assertValues(resp.values(), List.of(List.of(1), List.of(6)));
42-
}
43-
}
44-
4536
public void testSimpleWhereMatch() {
4637
var query = """
4738
FROM test
@@ -273,6 +264,60 @@ public void testMatchWithinEval() {
273264
assertThat(error.getMessage(), containsString("[MATCH] function is only supported in WHERE commands"));
274265
}
275266

267+
public void testDisjunctionScoring() {
268+
var query = """
269+
FROM test METADATA _score
270+
| WHERE match(content, "fox") OR length(content) < 20
271+
| KEEP id, _score
272+
| SORT _score DESC
273+
""";
274+
275+
try (var resp = run(query)) {
276+
assertColumnNames(resp.columns(), List.of("id", "_score"));
277+
assertColumnTypes(resp.columns(), List.of("integer", "double"));
278+
List<List<Object>> values = EsqlTestUtils.getValuesList(resp);
279+
assertThat(values.size(), equalTo(3));
280+
281+
assertThat(values.get(0).get(0), equalTo(1));
282+
assertThat(values.get(1).get(0), equalTo(2));
283+
assertThat(values.get(2).get(0), equalTo(6));
284+
285+
// Matches full text query and non pushable query
286+
assertThat((Double)values.get(0).get(1), greaterThan(2.0));
287+
// Matches just non pushable query
288+
assertThat((Double)values.get(1).get(1), equalTo(1));
289+
// Matches just full text query
290+
assertThat((Double)values.get(2).get(1), lessThan(1.0));
291+
assertThat((Double)values.get(2).get(1), greaterThan(0.0));
292+
}
293+
}
294+
295+
public void testDisjunctionScoringMultipleNonPushableFunctions() {
296+
var query = """
297+
FROM test METADATA _score
298+
| WHERE match(content, "fox") OR length(content) < 20 AND id > 2
299+
| KEEP id, _score
300+
| SORT _score DESC
301+
""";
302+
303+
try (var resp = run(query)) {
304+
assertColumnNames(resp.columns(), List.of("id", "_score"));
305+
assertColumnTypes(resp.columns(), List.of("integer", "double"));
306+
List<List<Object>> values = EsqlTestUtils.getValuesList(resp);
307+
assertThat(values.size(), equalTo(2));
308+
309+
assertThat(values.get(0).get(0), equalTo(1));
310+
assertThat(values.get(1).get(0), equalTo(6));
311+
312+
// Matches the full text query and a non pushable query
313+
assertThat((Double)values.get(0).get(1), greaterThan(1.0));
314+
assertThat((Double)values.get(0).get(1), lessThan(2.0));
315+
// Matches just the match function
316+
assertThat((Double)values.get(1).get(1), lessThan(1.0));
317+
assertThat((Double)values.get(1).get(1), greaterThan(0.0));
318+
}
319+
}
320+
276321
private void createAndPopulateIndex() {
277322
var indexName = "test";
278323
var client = client().admin().indices();

0 commit comments

Comments
 (0)