This is an automated email from the ASF dual-hosted git repository.

airborne pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new ee7bfe38940 [fix](search) Validate mode parameter in search() DSL 
options (#60785)
ee7bfe38940 is described below

commit ee7bfe3894064c2fbc8984d4f1cd6deec4260d39
Author: Jack <[email protected]>
AuthorDate: Tue Feb 24 21:53:38 2026 +0800

    [fix](search) Validate mode parameter in search() DSL options (#60785)
    
    ### What problem does this PR solve?
    
    Issue Number: close #DORIS-24352
    
    Problem Summary:
    When using `search()` with an invalid `mode` value in the options JSON
    (e.g., `"mode":"lucenedfafa"`), the query silently falls back to
    standard mode instead of reporting an error. This makes it difficult for
    users to detect typos or misconfiguration.
    
    This PR adds validation in `SearchOptions.validate()` to reject any mode
    value other than `"standard"` or `"lucene"`, throwing a clear error
    message.
    
    ### Release note
    
    Fix search() DSL to report an error when an invalid mode value is
    specified instead of silently falling back to standard mode.
---
 .../trees/expressions/functions/scalar/SearchDslParser.java  | 10 ++++++++++
 .../expressions/functions/scalar/SearchDslParserTest.java    | 12 ++++++++++++
 2 files changed, 22 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SearchDslParser.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SearchDslParser.java
index db12e715bed..bf0bc8f6168 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SearchDslParser.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SearchDslParser.java
@@ -1834,12 +1834,22 @@ public class SearchDslParser {
         /**
          * Validate the options after deserialization.
          * Checks for:
+         * - mode is "standard" or "lucene"
          * - Mutual exclusion between fields and default_field
          * - minimum_should_match is non-negative if specified
          *
          * @throws IllegalArgumentException if validation fails
          */
         public void validate() {
+            // Validation: mode must be "standard" or "lucene"
+            if (mode != null) {
+                String normalizedMode = mode.trim().toLowerCase();
+                if (!"standard".equals(normalizedMode) && 
!"lucene".equals(normalizedMode)) {
+                    throw new IllegalArgumentException(
+                            "'mode' must be 'standard' or 'lucene', got: " + 
mode);
+                }
+                this.mode = normalizedMode;
+            }
             // Validation: fields and default_field are mutually exclusive
             if (fields != null && !fields.isEmpty()
                     && defaultField != null && !defaultField.isEmpty()) {
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SearchDslParserTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SearchDslParserTest.java
index 9b40b05305e..01bbcf8d925 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SearchDslParserTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/functions/scalar/SearchDslParserTest.java
@@ -1617,6 +1617,18 @@ public class SearchDslParserTest {
         });
     }
 
+    @Test
+    public void testInvalidMode() {
+        // Test: invalid mode value should throw exception
+        String dsl = "hello";
+        String options = 
"{\"default_field\":\"title\",\"mode\":\"lucenedfafa\"}";
+
+        IllegalArgumentException exception = 
Assertions.assertThrows(IllegalArgumentException.class, () -> {
+            SearchDslParser.parseDsl(dsl, options);
+        });
+        Assertions.assertTrue(exception.getMessage().contains("'mode' must be 
'standard' or 'lucene'"));
+    }
+
     @Test
     public void testMultiFieldSingleTermSameResultForBothTypes() {
         // Test: single term should have same structure for both types


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to