@@ -2122,7 +2122,7 @@ def test_profile_query_params(client):
2122
2122
client .hset ("b" , "v" , "aaaabaaa" )
2123
2123
client .hset ("c" , "v" , "aaaaabaa" )
2124
2124
query = "*=>[KNN 2 @v $vec]"
2125
- q = Query (query ).return_field ("__v_score" ).sort_by ("__v_score" , True ). dialect ( 2 )
2125
+ q = Query (query ).return_field ("__v_score" ).sort_by ("__v_score" , True )
2126
2126
if is_resp2_connection (client ):
2127
2127
res , det = client .ft ().profile (q , query_params = {"vec" : "aaaaaaaa" })
2128
2128
assert det ["Iterators profile" ]["Counter" ] == 2.0
@@ -2155,7 +2155,7 @@ def test_vector_field(client):
2155
2155
client .hset ("c" , "v" , "aaaaabaa" )
2156
2156
2157
2157
query = "*=>[KNN 2 @v $vec]"
2158
- q = Query (query ).return_field ("__v_score" ).sort_by ("__v_score" , True ). dialect ( 2 )
2158
+ q = Query (query ).return_field ("__v_score" ).sort_by ("__v_score" , True )
2159
2159
res = client .ft ().search (q , query_params = {"vec" : "aaaaaaaa" })
2160
2160
2161
2161
if is_resp2_connection (client ):
@@ -2191,7 +2191,7 @@ def test_text_params(client):
2191
2191
client .hset ("doc3" , mapping = {"name" : "Carol" })
2192
2192
2193
2193
params_dict = {"name1" : "Alice" , "name2" : "Bob" }
2194
- q = Query ("@name:($name1 | $name2 )" ). dialect ( 2 )
2194
+ q = Query ("@name:($name1 | $name2 )" )
2195
2195
res = client .ft ().search (q , query_params = params_dict )
2196
2196
if is_resp2_connection (client ):
2197
2197
assert 2 == res .total
@@ -2214,7 +2214,7 @@ def test_numeric_params(client):
2214
2214
client .hset ("doc3" , mapping = {"numval" : 103 })
2215
2215
2216
2216
params_dict = {"min" : 101 , "max" : 102 }
2217
- q = Query ("@numval:[$min $max]" ). dialect ( 2 )
2217
+ q = Query ("@numval:[$min $max]" )
2218
2218
res = client .ft ().search (q , query_params = params_dict )
2219
2219
2220
2220
if is_resp2_connection (client ):
@@ -2236,7 +2236,7 @@ def test_geo_params(client):
2236
2236
client .hset ("doc3" , mapping = {"g" : "29.68746, 34.94882" })
2237
2237
2238
2238
params_dict = {"lat" : "34.95126" , "lon" : "29.69465" , "radius" : 1000 , "units" : "km" }
2239
- q = Query ("@g:[$lon $lat $radius $units]" ). dialect ( 2 )
2239
+ q = Query ("@g:[$lon $lat $radius $units]" )
2240
2240
res = client .ft ().search (q , query_params = params_dict )
2241
2241
_assert_search_result (client , res , ["doc1" , "doc2" , "doc3" ])
2242
2242
@@ -2355,19 +2355,19 @@ def test_dialect(client):
2355
2355
with pytest .raises (redis .ResponseError ) as err :
2356
2356
client .ft ().explain (Query ("(*)" ).dialect (1 ))
2357
2357
assert "Syntax error" in str (err )
2358
- assert "WILDCARD" in client .ft ().explain (Query ("(*)" ). dialect ( 2 ) )
2358
+ assert "WILDCARD" in client .ft ().explain (Query ("(*)" ))
2359
2359
2360
2360
with pytest .raises (redis .ResponseError ) as err :
2361
2361
client .ft ().explain (Query ("$hello" ).dialect (1 ))
2362
2362
assert "Syntax error" in str (err )
2363
- q = Query ("$hello" ). dialect ( 2 )
2363
+ q = Query ("$hello" )
2364
2364
expected = "UNION {\n hello\n +hello(expanded)\n }\n "
2365
2365
assert expected in client .ft ().explain (q , query_params = {"hello" : "hello" })
2366
2366
2367
2367
expected = "NUMERIC {0.000000 <= @num <= 10.000000}\n "
2368
2368
assert expected in client .ft ().explain (Query ("@title:(@num:[0 10])" ).dialect (1 ))
2369
2369
with pytest .raises (redis .ResponseError ) as err :
2370
- client .ft ().explain (Query ("@title:(@num:[0 10])" ). dialect ( 2 ) )
2370
+ client .ft ().explain (Query ("@title:(@num:[0 10])" ))
2371
2371
assert "Syntax error" in str (err )
2372
2372
2373
2373
@@ -2438,9 +2438,9 @@ def test_withsuffixtrie(client: redis.Redis):
2438
2438
@pytest .mark .redismod
2439
2439
def test_query_timeout (r : redis .Redis ):
2440
2440
q1 = Query ("foo" ).timeout (5000 )
2441
- assert q1 .get_args () == ["foo" , "TIMEOUT" , 5000 , "LIMIT" , 0 , 10 ]
2441
+ assert q1 .get_args () == ["foo" , "TIMEOUT" , 5000 , "DIALECT" , 2 , " LIMIT" , 0 , 10 ]
2442
2442
q1 = Query ("foo" ).timeout (0 )
2443
- assert q1 .get_args () == ["foo" , "TIMEOUT" , 0 , "LIMIT" , 0 , 10 ]
2443
+ assert q1 .get_args () == ["foo" , "TIMEOUT" , 0 , "DIALECT" , 2 , " LIMIT" , 0 , 10 ]
2444
2444
q2 = Query ("foo" ).timeout ("not_a_number" )
2445
2445
with pytest .raises (redis .ResponseError ):
2446
2446
r .ft ().search (q2 )
@@ -2507,28 +2507,26 @@ def test_search_missing_fields(client):
2507
2507
)
2508
2508
2509
2509
with pytest .raises (redis .exceptions .ResponseError ) as e :
2510
- client .ft ().search (
2511
- Query ("ismissing(@title)" ).dialect (2 ).return_field ("id" ).no_content ()
2512
- )
2510
+ client .ft ().search (Query ("ismissing(@title)" ).return_field ("id" ).no_content ())
2513
2511
assert "to be defined with 'INDEXMISSING'" in e .value .args [0 ]
2514
2512
2515
2513
res = client .ft ().search (
2516
- Query ("ismissing(@features)" ).dialect ( 2 ). return_field ("id" ).no_content ()
2514
+ Query ("ismissing(@features)" ).return_field ("id" ).no_content ()
2517
2515
)
2518
2516
_assert_search_result (client , res , ["property:2" ])
2519
2517
2520
2518
res = client .ft ().search (
2521
- Query ("-ismissing(@features)" ).dialect ( 2 ). return_field ("id" ).no_content ()
2519
+ Query ("-ismissing(@features)" ).return_field ("id" ).no_content ()
2522
2520
)
2523
2521
_assert_search_result (client , res , ["property:1" , "property:3" ])
2524
2522
2525
2523
res = client .ft ().search (
2526
- Query ("ismissing(@description)" ).dialect ( 2 ). return_field ("id" ).no_content ()
2524
+ Query ("ismissing(@description)" ).return_field ("id" ).no_content ()
2527
2525
)
2528
2526
_assert_search_result (client , res , ["property:3" ])
2529
2527
2530
2528
res = client .ft ().search (
2531
- Query ("-ismissing(@description)" ).dialect ( 2 ). return_field ("id" ).no_content ()
2529
+ Query ("-ismissing(@description)" ).return_field ("id" ).no_content ()
2532
2530
)
2533
2531
_assert_search_result (client , res , ["property:1" , "property:2" ])
2534
2532
@@ -2578,31 +2576,25 @@ def test_search_empty_fields(client):
2578
2576
)
2579
2577
2580
2578
with pytest .raises (redis .exceptions .ResponseError ) as e :
2581
- client .ft ().search (
2582
- Query ("@title:''" ).dialect (2 ).return_field ("id" ).no_content ()
2583
- )
2579
+ client .ft ().search (Query ("@title:''" ).return_field ("id" ).no_content ())
2584
2580
assert "Use `INDEXEMPTY` in field creation" in e .value .args [0 ]
2585
2581
2586
2582
res = client .ft ().search (
2587
- Query ("@features:{$empty}" ).dialect ( 2 ). return_field ("id" ).no_content (),
2583
+ Query ("@features:{$empty}" ).return_field ("id" ).no_content (),
2588
2584
query_params = {"empty" : "" },
2589
2585
)
2590
2586
_assert_search_result (client , res , ["property:2" ])
2591
2587
2592
2588
res = client .ft ().search (
2593
- Query ("-@features:{$empty}" ).dialect ( 2 ). return_field ("id" ).no_content (),
2589
+ Query ("-@features:{$empty}" ).return_field ("id" ).no_content (),
2594
2590
query_params = {"empty" : "" },
2595
2591
)
2596
2592
_assert_search_result (client , res , ["property:1" , "property:3" ])
2597
2593
2598
- res = client .ft ().search (
2599
- Query ("@description:''" ).dialect (2 ).return_field ("id" ).no_content ()
2600
- )
2594
+ res = client .ft ().search (Query ("@description:''" ).return_field ("id" ).no_content ())
2601
2595
_assert_search_result (client , res , ["property:3" ])
2602
2596
2603
- res = client .ft ().search (
2604
- Query ("-@description:''" ).dialect (2 ).return_field ("id" ).no_content ()
2605
- )
2597
+ res = client .ft ().search (Query ("-@description:''" ).return_field ("id" ).no_content ())
2606
2598
_assert_search_result (client , res , ["property:1" , "property:2" ])
2607
2599
2608
2600
@@ -2643,29 +2635,85 @@ def test_special_characters_in_fields(client):
2643
2635
2644
2636
# no need to escape - when using params
2645
2637
res = client .ft ().search (
2646
- Query ("@uuid:{$uuid}" ). dialect ( 2 ) ,
2638
+ Query ("@uuid:{$uuid}" ),
2647
2639
query_params = {"uuid" : "123e4567-e89b-12d3-a456-426614174000" },
2648
2640
)
2649
2641
_assert_search_result (client , res , ["resource:1" ])
2650
2642
2651
2643
# with double quotes exact match no need to escape the - even without params
2652
- res = client .ft ().search (
2653
- Query ('@uuid:{"123e4567-e89b-12d3-a456-426614174000"}' ).dialect (2 )
2654
- )
2644
+ res = client .ft ().search (Query ('@uuid:{"123e4567-e89b-12d3-a456-426614174000"}' ))
2655
2645
_assert_search_result (client , res , ["resource:1" ])
2656
2646
2657
- res = client .ft ().search (Query ('@tags:{"new-year\' s-resolutions"}' ). dialect ( 2 ) )
2647
+ res = client .ft ().search (Query ('@tags:{"new-year\' s-resolutions"}' ))
2658
2648
_assert_search_result (client , res , ["resource:2" ])
2659
2649
2660
2650
# possible to search numeric fields by single value
2661
- res = client .ft ().search (Query ("@rating:[4]" ). dialect ( 2 ) )
2651
+ res = client .ft ().search (Query ("@rating:[4]" ))
2662
2652
_assert_search_result (client , res , ["resource:2" ])
2663
2653
2664
2654
# some chars still need escaping
2665
- res = client .ft ().search (Query (r"@tags:{\$btc}" ). dialect ( 2 ) )
2655
+ res = client .ft ().search (Query (r"@tags:{\$btc}" ))
2666
2656
_assert_search_result (client , res , ["resource:1" ])
2667
2657
2668
2658
2659
+ @pytest .mark .redismod
2660
+ @skip_ifmodversion_lt ("2.4.3" , "search" )
2661
+ def test_vector_search_with_default_dialect (client ):
2662
+ client .ft ().create_index (
2663
+ (
2664
+ VectorField (
2665
+ "v" , "HNSW" , {"TYPE" : "FLOAT32" , "DIM" : 2 , "DISTANCE_METRIC" : "L2" }
2666
+ ),
2667
+ )
2668
+ )
2669
+
2670
+ client .hset ("a" , "v" , "aaaaaaaa" )
2671
+ client .hset ("b" , "v" , "aaaabaaa" )
2672
+ client .hset ("c" , "v" , "aaaaabaa" )
2673
+
2674
+ query = "*=>[KNN 2 @v $vec]"
2675
+ q = Query (query )
2676
+
2677
+ assert "DIALECT" in q .get_args ()
2678
+ assert 2 in q .get_args ()
2679
+
2680
+ res = client .ft ().search (q , query_params = {"vec" : "aaaaaaaa" })
2681
+ if is_resp2_connection (client ):
2682
+ assert res .total == 2
2683
+ else :
2684
+ assert res ["total_results" ] == 2
2685
+
2686
+
2687
+ @pytest .mark .redismod
2688
+ @skip_ifmodversion_lt ("2.4.3" , "search" )
2689
+ def test_search_query_with_different_dialects (client ):
2690
+ client .ft ().create_index (
2691
+ (TextField ("name" ), TextField ("lastname" )),
2692
+ definition = IndexDefinition (prefix = ["test:" ]),
2693
+ )
2694
+
2695
+ client .hset ("test:1" , "name" , "James" )
2696
+ client .hset ("test:1" , "lastname" , "Brown" )
2697
+
2698
+ # Query with default DIALECT 2
2699
+ query = "@name: James Brown"
2700
+ q = Query (query )
2701
+ res = client .ft ().search (q )
2702
+ if is_resp2_connection (client ):
2703
+ assert res .total == 1
2704
+ else :
2705
+ assert res ["total_results" ] == 1
2706
+
2707
+ # Query with explicit DIALECT 1
2708
+ query = "@name: James Brown"
2709
+ q = Query (query ).dialect (1 )
2710
+ res = client .ft ().search (q )
2711
+ if is_resp2_connection (client ):
2712
+ assert res .total == 0
2713
+ else :
2714
+ assert res ["total_results" ] == 0
2715
+
2716
+
2669
2717
def _assert_search_result (client , result , expected_doc_ids ):
2670
2718
"""
2671
2719
Make sure the result of a geo search is as expected, taking into account the RESP
0 commit comments