@@ -1542,7 +1542,8 @@ def test_vector_field(modclient):
1542
1542
modclient .hset ("b" , "v" , "aaaabaaa" )
1543
1543
modclient .hset ("c" , "v" , "aaaaabaa" )
1544
1544
1545
- q = Query ("*=>[KNN 2 @v $vec]" ).return_field ("__v_score" ).sort_by ("__v_score" , True )
1545
+ query = "*=>[KNN 2 @v $vec]"
1546
+ q = Query (query ).return_field ("__v_score" ).sort_by ("__v_score" , True ).dialect (2 )
1546
1547
res = modclient .ft ().search (q , query_params = {"vec" : "aaaaaaaa" })
1547
1548
1548
1549
assert "a" == res .docs [0 ].id
@@ -1572,7 +1573,7 @@ def test_text_params(modclient):
1572
1573
modclient .ft ().add_document ("doc3" , name = "Carol" )
1573
1574
1574
1575
params_dict = {"name1" : "Alice" , "name2" : "Bob" }
1575
- q = Query ("@name:($name1 | $name2 )" )
1576
+ q = Query ("@name:($name1 | $name2 )" ). dialect ( 2 )
1576
1577
res = modclient .ft ().search (q , query_params = params_dict )
1577
1578
assert 2 == res .total
1578
1579
assert "doc1" == res .docs [0 ].id
@@ -1589,7 +1590,7 @@ def test_numeric_params(modclient):
1589
1590
modclient .ft ().add_document ("doc3" , numval = 103 )
1590
1591
1591
1592
params_dict = {"min" : 101 , "max" : 102 }
1592
- q = Query ("@numval:[$min $max]" )
1593
+ q = Query ("@numval:[$min $max]" ). dialect ( 2 )
1593
1594
res = modclient .ft ().search (q , query_params = params_dict )
1594
1595
1595
1596
assert 2 == res .total
@@ -1607,7 +1608,7 @@ def test_geo_params(modclient):
1607
1608
modclient .ft ().add_document ("doc3" , g = "29.68746, 34.94882" )
1608
1609
1609
1610
params_dict = {"lat" : "34.95126" , "lon" : "29.69465" , "radius" : 1000 , "units" : "km" }
1610
- q = Query ("@g:[$lon $lat $radius $units]" )
1611
+ q = Query ("@g:[$lon $lat $radius $units]" ). dialect ( 2 )
1611
1612
res = modclient .ft ().search (q , query_params = params_dict )
1612
1613
assert 3 == res .total
1613
1614
assert "doc1" == res .docs [0 ].id
@@ -1631,3 +1632,48 @@ def test_search_commands_in_pipeline(client):
1631
1632
assert "foo baz" == res [3 ][2 ]
1632
1633
assert res [3 ][5 ] is None
1633
1634
assert res [3 ][3 ] == res [3 ][6 ] == ["txt" , "foo bar" ]
1635
+
1636
+
1637
+ @pytest .mark .redismod
1638
+ @pytest .mark .onlynoncluster
1639
+ @skip_ifmodversion_lt ("2.4.3" , "search" )
1640
+ def test_dialect_config (modclient : redis .Redis ):
1641
+ assert modclient .ft ().config_get ("DEFAULT_DIALECT" ) == {"DEFAULT_DIALECT" : "1" }
1642
+ assert modclient .ft ().config_set ("DEFAULT_DIALECT" , 2 )
1643
+ assert modclient .ft ().config_get ("DEFAULT_DIALECT" ) == {"DEFAULT_DIALECT" : "2" }
1644
+ with pytest .raises (redis .ResponseError ):
1645
+ modclient .ft ().config_set ("DEFAULT_DIALECT" , 0 )
1646
+
1647
+
1648
+ @pytest .mark .redismod
1649
+ @skip_ifmodversion_lt ("2.4.3" , "search" )
1650
+ def test_dialect (modclient : redis .Redis ):
1651
+ modclient .ft ().create_index (
1652
+ (
1653
+ TagField ("title" ),
1654
+ TextField ("t1" ),
1655
+ TextField ("t2" ),
1656
+ NumericField ("num" ),
1657
+ VectorField (
1658
+ "v" , "HNSW" , {"TYPE" : "FLOAT32" , "DIM" : 1 , "DISTANCE_METRIC" : "COSINE" }
1659
+ ),
1660
+ )
1661
+ )
1662
+ modclient .hset ("h" , "t1" , "hello" )
1663
+ with pytest .raises (redis .ResponseError ) as err :
1664
+ modclient .ft ().explain (Query ("(*)" ).dialect (1 ))
1665
+ assert "Syntax error" in str (err )
1666
+ assert "WILDCARD" in modclient .ft ().explain (Query ("(*)" ).dialect (2 ))
1667
+
1668
+ with pytest .raises (redis .ResponseError ) as err :
1669
+ modclient .ft ().explain (Query ("$hello" ).dialect (1 ))
1670
+ assert "Syntax error" in str (err )
1671
+ q = Query ("$hello" ).dialect (2 )
1672
+ expected = "UNION {\n hello\n +hello(expanded)\n }\n "
1673
+ assert expected in modclient .ft ().explain (q , query_params = {"hello" : "hello" })
1674
+
1675
+ expected = "NUMERIC {0.000000 <= @num <= 10.000000}\n "
1676
+ assert expected in modclient .ft ().explain (Query ("@title:(@num:[0 10])" ).dialect (1 ))
1677
+ with pytest .raises (redis .ResponseError ) as err :
1678
+ modclient .ft ().explain (Query ("@title:(@num:[0 10])" ).dialect (2 ))
1679
+ assert "Syntax error" in str (err )
0 commit comments