Skip to content

Commit ce72b33

Browse files
branch-4.0: [fix](search) Validate mode parameter in search() DSL options #60785 (#60813)
Cherry-picked from #60785 Co-authored-by: Jack <jiangkai@selectdb.com>
1 parent a133581 commit ce72b33

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SearchDslParser.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,12 +1779,22 @@ public boolean isCrossFieldsMode() {
17791779
/**
17801780
* Validate the options after deserialization.
17811781
* Checks for:
1782+
* - mode is "standard" or "lucene"
17821783
* - Mutual exclusion between fields and default_field
17831784
* - minimum_should_match is non-negative if specified
17841785
*
17851786
* @throws IllegalArgumentException if validation fails
17861787
*/
17871788
public void validate() {
1789+
// Validation: mode must be "standard" or "lucene"
1790+
if (mode != null) {
1791+
String normalizedMode = mode.trim().toLowerCase();
1792+
if (!"standard".equals(normalizedMode) && !"lucene".equals(normalizedMode)) {
1793+
throw new IllegalArgumentException(
1794+
"'mode' must be 'standard' or 'lucene', got: " + mode);
1795+
}
1796+
this.mode = normalizedMode;
1797+
}
17881798
// Validation: fields and default_field are mutually exclusive
17891799
if (fields != null && !fields.isEmpty()
17901800
&& defaultField != null && !defaultField.isEmpty()) {

fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SearchDslParserTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,18 @@ public void testMultiFieldInvalidType() {
13011301
});
13021302
}
13031303

1304+
@Test
1305+
public void testInvalidMode() {
1306+
// Test: invalid mode value should throw exception
1307+
String dsl = "hello";
1308+
String options = "{\"default_field\":\"title\",\"mode\":\"lucenedfafa\"}";
1309+
1310+
IllegalArgumentException exception = Assertions.assertThrows(IllegalArgumentException.class, () -> {
1311+
SearchDslParser.parseDsl(dsl, options);
1312+
});
1313+
Assertions.assertTrue(exception.getMessage().contains("'mode' must be 'standard' or 'lucene'"));
1314+
}
1315+
13041316
@Test
13051317
public void testMultiFieldSingleTermSameResultForBothTypes() {
13061318
// Test: single term should have same structure for both types

0 commit comments

Comments
 (0)