Skip to content

Commit 0d93fda

Browse files
committed
Improved the parsing tests
1 parent 591d644 commit 0d93fda

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

x-pack/plugin/rank-rrf/src/test/java/org/elasticsearch/xpack/rank/rrf/RRFRetrieverBuilderParsingTests.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,66 @@ public void testSimplifiedWeightedRRFBasicParsing() throws IOException {
431431
}
432432
}
433433

434+
public void testSimplifiedFieldSyntaxVariations() throws IOException {
435+
// Test parsing succeeds with various field syntax variations (validation happens during rewrite, not parsing)
436+
SearchUsageHolder searchUsageHolder = new UsageService().getSearchUsageHolder();
437+
438+
// Test 1: Pure object-based syntax
439+
String restContent1 = """
440+
{
441+
"retriever": {
442+
"rrf": {
443+
"fields": [
444+
{"field": "name", "weight": 2.0},
445+
{"field": "description", "weight": 1.0}
446+
],
447+
"query": "test"
448+
}
449+
}
450+
}
451+
""";
452+
453+
// Test 2: Mixed syntax (object-based + plain strings)
454+
String restContent2 = """
455+
{
456+
"retriever": {
457+
"rrf": {
458+
"fields": [
459+
{"field": "name", "weight": 3.0},
460+
"description",
461+
{"field": "category", "weight": 0.5}
462+
],
463+
"query": "test"
464+
}
465+
}
466+
}
467+
""";
468+
469+
// Test 3: Field^weight syntax
470+
String restContent3 = """
471+
{
472+
"retriever": {
473+
"rrf": {
474+
"fields": ["name^2", "description^0.5"],
475+
"query": "test"
476+
}
477+
}
478+
}
479+
""";
480+
481+
// All three should parse successfully
482+
for (String restContent : List.of(restContent1, restContent2, restContent3)) {
483+
try (XContentParser jsonParser = createParser(JsonXContent.jsonXContent, restContent)) {
484+
SearchSourceBuilder source = new SearchSourceBuilder().parseXContent(jsonParser, true, searchUsageHolder, nf -> true);
485+
assertThat(source.retriever(), instanceOf(RRFRetrieverBuilder.class));
486+
487+
RRFRetrieverBuilder rrfRetrieverBuilder = (RRFRetrieverBuilder) source.retriever();
488+
// Should parse successfully - validation happens during rewrite phase
489+
assertNotNull(rrfRetrieverBuilder);
490+
}
491+
}
492+
}
493+
434494
private void expectParsingException(String restContent, String expectedMessageFragment) throws IOException {
435495
SearchUsageHolder searchUsageHolder = new UsageService().getSearchUsageHolder();
436496
try (XContentParser jsonParser = createParser(JsonXContent.jsonXContent, restContent)) {

0 commit comments

Comments
 (0)