@@ -2122,7 +2122,7 @@ def test_profile_query_params(client):
21222122 client .hset ("b" , "v" , "aaaabaaa" )
21232123 client .hset ("c" , "v" , "aaaaabaa" )
21242124 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 )
21262126 if is_resp2_connection (client ):
21272127 res , det = client .ft ().profile (q , query_params = {"vec" : "aaaaaaaa" })
21282128 assert det ["Iterators profile" ]["Counter" ] == 2.0
@@ -2155,7 +2155,7 @@ def test_vector_field(client):
21552155 client .hset ("c" , "v" , "aaaaabaa" )
21562156
21572157 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 )
21592159 res = client .ft ().search (q , query_params = {"vec" : "aaaaaaaa" })
21602160
21612161 if is_resp2_connection (client ):
@@ -2191,7 +2191,7 @@ def test_text_params(client):
21912191 client .hset ("doc3" , mapping = {"name" : "Carol" })
21922192
21932193 params_dict = {"name1" : "Alice" , "name2" : "Bob" }
2194- q = Query ("@name:($name1 | $name2 )" ). dialect ( 2 )
2194+ q = Query ("@name:($name1 | $name2 )" )
21952195 res = client .ft ().search (q , query_params = params_dict )
21962196 if is_resp2_connection (client ):
21972197 assert 2 == res .total
@@ -2214,7 +2214,7 @@ def test_numeric_params(client):
22142214 client .hset ("doc3" , mapping = {"numval" : 103 })
22152215
22162216 params_dict = {"min" : 101 , "max" : 102 }
2217- q = Query ("@numval:[$min $max]" ). dialect ( 2 )
2217+ q = Query ("@numval:[$min $max]" )
22182218 res = client .ft ().search (q , query_params = params_dict )
22192219
22202220 if is_resp2_connection (client ):
@@ -2236,7 +2236,7 @@ def test_geo_params(client):
22362236 client .hset ("doc3" , mapping = {"g" : "29.68746, 34.94882" })
22372237
22382238 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]" )
22402240 res = client .ft ().search (q , query_params = params_dict )
22412241 _assert_search_result (client , res , ["doc1" , "doc2" , "doc3" ])
22422242
@@ -2355,19 +2355,19 @@ def test_dialect(client):
23552355 with pytest .raises (redis .ResponseError ) as err :
23562356 client .ft ().explain (Query ("(*)" ).dialect (1 ))
23572357 assert "Syntax error" in str (err )
2358- assert "WILDCARD" in client .ft ().explain (Query ("(*)" ). dialect ( 2 ) )
2358+ assert "WILDCARD" in client .ft ().explain (Query ("(*)" ))
23592359
23602360 with pytest .raises (redis .ResponseError ) as err :
23612361 client .ft ().explain (Query ("$hello" ).dialect (1 ))
23622362 assert "Syntax error" in str (err )
2363- q = Query ("$hello" ). dialect ( 2 )
2363+ q = Query ("$hello" )
23642364 expected = "UNION {\n hello\n +hello(expanded)\n }\n "
23652365 assert expected in client .ft ().explain (q , query_params = {"hello" : "hello" })
23662366
23672367 expected = "NUMERIC {0.000000 <= @num <= 10.000000}\n "
23682368 assert expected in client .ft ().explain (Query ("@title:(@num:[0 10])" ).dialect (1 ))
23692369 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])" ))
23712371 assert "Syntax error" in str (err )
23722372
23732373
@@ -2438,9 +2438,9 @@ def test_withsuffixtrie(client: redis.Redis):
24382438@pytest .mark .redismod
24392439def test_query_timeout (r : redis .Redis ):
24402440 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 ]
24422442 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 ]
24442444 q2 = Query ("foo" ).timeout ("not_a_number" )
24452445 with pytest .raises (redis .ResponseError ):
24462446 r .ft ().search (q2 )
@@ -2507,28 +2507,26 @@ def test_search_missing_fields(client):
25072507 )
25082508
25092509 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 ())
25132511 assert "to be defined with 'INDEXMISSING'" in e .value .args [0 ]
25142512
25152513 res = client .ft ().search (
2516- Query ("ismissing(@features)" ).dialect ( 2 ). return_field ("id" ).no_content ()
2514+ Query ("ismissing(@features)" ).return_field ("id" ).no_content ()
25172515 )
25182516 _assert_search_result (client , res , ["property:2" ])
25192517
25202518 res = client .ft ().search (
2521- Query ("-ismissing(@features)" ).dialect ( 2 ). return_field ("id" ).no_content ()
2519+ Query ("-ismissing(@features)" ).return_field ("id" ).no_content ()
25222520 )
25232521 _assert_search_result (client , res , ["property:1" , "property:3" ])
25242522
25252523 res = client .ft ().search (
2526- Query ("ismissing(@description)" ).dialect ( 2 ). return_field ("id" ).no_content ()
2524+ Query ("ismissing(@description)" ).return_field ("id" ).no_content ()
25272525 )
25282526 _assert_search_result (client , res , ["property:3" ])
25292527
25302528 res = client .ft ().search (
2531- Query ("-ismissing(@description)" ).dialect ( 2 ). return_field ("id" ).no_content ()
2529+ Query ("-ismissing(@description)" ).return_field ("id" ).no_content ()
25322530 )
25332531 _assert_search_result (client , res , ["property:1" , "property:2" ])
25342532
@@ -2578,31 +2576,25 @@ def test_search_empty_fields(client):
25782576 )
25792577
25802578 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 ())
25842580 assert "Use `INDEXEMPTY` in field creation" in e .value .args [0 ]
25852581
25862582 res = client .ft ().search (
2587- Query ("@features:{$empty}" ).dialect ( 2 ). return_field ("id" ).no_content (),
2583+ Query ("@features:{$empty}" ).return_field ("id" ).no_content (),
25882584 query_params = {"empty" : "" },
25892585 )
25902586 _assert_search_result (client , res , ["property:2" ])
25912587
25922588 res = client .ft ().search (
2593- Query ("-@features:{$empty}" ).dialect ( 2 ). return_field ("id" ).no_content (),
2589+ Query ("-@features:{$empty}" ).return_field ("id" ).no_content (),
25942590 query_params = {"empty" : "" },
25952591 )
25962592 _assert_search_result (client , res , ["property:1" , "property:3" ])
25972593
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 ())
26012595 _assert_search_result (client , res , ["property:3" ])
26022596
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 ())
26062598 _assert_search_result (client , res , ["property:1" , "property:2" ])
26072599
26082600
@@ -2643,29 +2635,85 @@ def test_special_characters_in_fields(client):
26432635
26442636 # no need to escape - when using params
26452637 res = client .ft ().search (
2646- Query ("@uuid:{$uuid}" ). dialect ( 2 ) ,
2638+ Query ("@uuid:{$uuid}" ),
26472639 query_params = {"uuid" : "123e4567-e89b-12d3-a456-426614174000" },
26482640 )
26492641 _assert_search_result (client , res , ["resource:1" ])
26502642
26512643 # 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"}' ))
26552645 _assert_search_result (client , res , ["resource:1" ])
26562646
2657- res = client .ft ().search (Query ('@tags:{"new-year\' s-resolutions"}' ). dialect ( 2 ) )
2647+ res = client .ft ().search (Query ('@tags:{"new-year\' s-resolutions"}' ))
26582648 _assert_search_result (client , res , ["resource:2" ])
26592649
26602650 # 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]" ))
26622652 _assert_search_result (client , res , ["resource:2" ])
26632653
26642654 # 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}" ))
26662656 _assert_search_result (client , res , ["resource:1" ])
26672657
26682658
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+
26692717def _assert_search_result (client , result , expected_doc_ids ):
26702718 """
26712719 Make sure the result of a geo search is as expected, taking into account the RESP
0 commit comments