@@ -54,6 +54,9 @@ suite("test_search_multi_field") {
5454 """
5555
5656 // Insert test data
57+ // Note: id=9 is specifically designed to test cross_fields vs best_fields behavior
58+ // - cross_fields: matches (title has 'machine', content has 'learning')
59+ // - best_fields: does NOT match (no single field has both terms)
5760 sql """ INSERT INTO ${ tableName} VALUES
5861 (1, 'machine learning basics', 'introduction to AI and ML', 'ml ai tutorial', 'tech'),
5962 (2, 'cooking recipes', 'how to make pasta', 'food cooking', 'lifestyle'),
@@ -62,7 +65,8 @@ suite("test_search_multi_field") {
6265 (5, 'learning guitar', 'music lessons for beginners', 'music learning', 'entertainment'),
6366 (6, 'deep learning neural networks', 'advanced AI concepts', 'ai ml deep', 'tech'),
6467 (7, 'car maintenance guide', 'vehicle repair tips', 'auto maintenance', 'automotive'),
65- (8, 'cooking machine reviews', 'kitchen appliance ratings', 'cooking appliances', 'lifestyle')
68+ (8, 'cooking machine reviews', 'kitchen appliance ratings', 'cooking appliances', 'lifestyle'),
69+ (9, 'machine guide', 'learning tips', 'howto', 'tech')
6670 """
6771
6872 // Wait for index building
@@ -86,6 +90,20 @@ suite("test_search_multi_field") {
8690 ORDER BY id
8791 """
8892
93+ // ============ Test 2b: Multiple terms with AND in Lucene mode ============
94+ // Same as Test 2 but with mode:lucene - should have same result
95+ // This tests that default_operator:and works correctly with Lucene mode
96+ // ES behavior comparison:
97+ // - ES best_fields (default): only id=1 (both terms must be in same field)
98+ // - ES cross_fields: id=1 and id=9 (terms can be across different fields)
99+ // - Doris uses cross_fields semantics
100+ qt_multi_field_multi_term_and_lucene """
101+ SELECT /*+SET_VAR(enable_common_expr_pushdown=true) */ id, title
102+ FROM ${ tableName}
103+ WHERE search('machine learning', '{"fields":["title","content"],"default_operator":"and","mode":"lucene"}')
104+ ORDER BY id
105+ """
106+
89107 // ============ Test 3: Multiple terms with OR (default) ============
90108 qt_multi_field_multi_term_or """
91109 SELECT /*+SET_VAR(enable_common_expr_pushdown=true) */ id, title
@@ -151,13 +169,29 @@ suite("test_search_multi_field") {
151169 """
152170
153171 // ============ Test 11: Multi-field with Lucene mode - simple AND ============
172+ // This is equivalent to Test 2 but uses Lucene mode with explicit AND operator
173+ // Expected: Same result as Test 2 - cross_fields semantics
174+ // - ES best_fields would return: id=1 only (both terms in same field)
175+ // - Doris cross_fields returns: id=1, id=9 (terms can be in different fields)
176+ // id=9: title='machine guide', content='learning tips' - matches cross_fields but not best_fields
154177 qt_multi_field_lucene_and """
155178 SELECT /*+SET_VAR(enable_common_expr_pushdown=true) */ id, title
156179 FROM ${ tableName}
157180 WHERE search('machine AND learning', '{"fields":["title","content"],"mode":"lucene","minimum_should_match":0}')
158181 ORDER BY id
159182 """
160183
184+ // ============ Test 11b: Verify cross_fields behavior explicitly ============
185+ // This test verifies that our implementation uses cross_fields semantics (like ES type:cross_fields)
186+ // Query: "machine AND learning" across title and content
187+ // id=9 has 'machine' in title and 'learning' in content - should match with cross_fields
188+ qt_multi_field_cross_fields_verify """
189+ SELECT /*+SET_VAR(enable_common_expr_pushdown=true) */ id, title, content
190+ FROM ${ tableName}
191+ WHERE search('machine AND learning', '{"fields":["title","content"]}')
192+ ORDER BY id
193+ """
194+
161195 // ============ Test 12: Multi-field with Lucene mode - OR ============
162196 qt_multi_field_lucene_or """
163197 SELECT /*+SET_VAR(enable_common_expr_pushdown=true) */ id, title
0 commit comments