@@ -314,6 +314,7 @@ def test_client(client):
314314
315315@pytest .mark .redismod
316316@pytest .mark .onlynoncluster
317+ @skip_if_server_version_gte ("7.9.0" )
317318def test_scores (client ):
318319 client .ft ().create_index ((TextField ("txt" ),))
319320
@@ -334,6 +335,29 @@ def test_scores(client):
334335 assert "doc1" == res ["results" ][1 ]["id" ]
335336
336337
338+ @pytest .mark .redismod
339+ @pytest .mark .onlynoncluster
340+ @skip_if_server_version_lt ("7.9.0" )
341+ def test_scores_with_new_default_scorer (client ):
342+ client .ft ().create_index ((TextField ("txt" ),))
343+
344+ client .hset ("doc1" , mapping = {"txt" : "foo baz" })
345+ client .hset ("doc2" , mapping = {"txt" : "foo bar" })
346+
347+ q = Query ("foo ~bar" ).with_scores ()
348+ res = client .ft ().search (q )
349+ if is_resp2_connection (client ):
350+ assert 2 == res .total
351+ assert "doc2" == res .docs [0 ].id
352+ assert 0.87 == pytest .approx (res .docs [0 ].score , 0.01 )
353+ assert "doc1" == res .docs [1 ].id
354+ else :
355+ assert 2 == res ["total_results" ]
356+ assert "doc2" == res ["results" ][0 ]["id" ]
357+ assert 0.87 == pytest .approx (res ["results" ][0 ]["score" ], 0.01 )
358+ assert "doc1" == res ["results" ][1 ]["id" ]
359+
360+
337361@pytest .mark .redismod
338362def test_stopwords (client ):
339363 client .ft ().create_index ((TextField ("txt" ),), stopwords = ["foo" , "bar" , "baz" ])
@@ -623,7 +647,7 @@ def test_summarize(client):
623647 createIndex (client .ft ())
624648 waitForIndex (client , getattr (client .ft (), "index_name" , "idx" ))
625649
626- q = Query ("king henry" ).paging (0 , 1 )
650+ q = Query (' "king henry"' ).paging (0 , 1 )
627651 q .highlight (fields = ("play" , "txt" ), tags = ("<b>" , "</b>" ))
628652 q .summarize ("txt" )
629653
@@ -635,7 +659,7 @@ def test_summarize(client):
635659 == doc .txt
636660 )
637661
638- q = Query ("king henry" ).paging (0 , 1 ).summarize ().highlight ()
662+ q = Query (' "king henry"' ).paging (0 , 1 ).summarize ().highlight ()
639663
640664 doc = sorted (client .ft ().search (q ).docs )[0 ]
641665 assert "<b>Henry</b> ... " == doc .play
@@ -651,7 +675,7 @@ def test_summarize(client):
651675 == doc ["extra_attributes" ]["txt" ]
652676 )
653677
654- q = Query ("king henry" ).paging (0 , 1 ).summarize ().highlight ()
678+ q = Query (' "king henry"' ).paging (0 , 1 ).summarize ().highlight ()
655679
656680 doc = sorted (client .ft ().search (q )["results" ])[0 ]
657681 assert "<b>Henry</b> ... " == doc ["extra_attributes" ]["play" ]
@@ -936,6 +960,7 @@ def test_phonetic_matcher(client):
936960@pytest .mark .onlynoncluster
937961# NOTE(imalinovskyi): This test contains hardcoded scores valid only for RediSearch 2.8+
938962@skip_ifmodversion_lt ("2.8.0" , "search" )
963+ @skip_if_server_version_gte ("7.9.0" )
939964def test_scorer (client ):
940965 client .ft ().create_index ((TextField ("description" ),))
941966
@@ -982,6 +1007,55 @@ def test_scorer(client):
9821007 assert 0.0 == res ["results" ][0 ]["score" ]
9831008
9841009
1010+ @pytest .mark .redismod
1011+ @pytest .mark .onlynoncluster
1012+ @skip_if_server_version_lt ("7.9.0" )
1013+ def test_scorer_with_new_default_scorer (client ):
1014+ client .ft ().create_index ((TextField ("description" ),))
1015+
1016+ client .hset (
1017+ "doc1" , mapping = {"description" : "The quick brown fox jumps over the lazy dog" }
1018+ )
1019+ client .hset (
1020+ "doc2" ,
1021+ mapping = {
1022+ "description" : "Quick alice was beginning to get very tired of sitting by her quick sister on the bank, and of having nothing to do." # noqa
1023+ },
1024+ )
1025+
1026+ # default scorer is BM25STD
1027+ if is_resp2_connection (client ):
1028+ res = client .ft ().search (Query ("quick" ).with_scores ())
1029+ assert 0.23 == pytest .approx (res .docs [0 ].score , 0.05 )
1030+ res = client .ft ().search (Query ("quick" ).scorer ("TFIDF" ).with_scores ())
1031+ assert 1.0 == res .docs [0 ].score
1032+ res = client .ft ().search (Query ("quick" ).scorer ("TFIDF.DOCNORM" ).with_scores ())
1033+ assert 0.14285714285714285 == res .docs [0 ].score
1034+ res = client .ft ().search (Query ("quick" ).scorer ("BM25" ).with_scores ())
1035+ assert 0.22471909420069797 == res .docs [0 ].score
1036+ res = client .ft ().search (Query ("quick" ).scorer ("DISMAX" ).with_scores ())
1037+ assert 2.0 == res .docs [0 ].score
1038+ res = client .ft ().search (Query ("quick" ).scorer ("DOCSCORE" ).with_scores ())
1039+ assert 1.0 == res .docs [0 ].score
1040+ res = client .ft ().search (Query ("quick" ).scorer ("HAMMING" ).with_scores ())
1041+ assert 0.0 == res .docs [0 ].score
1042+ else :
1043+ res = client .ft ().search (Query ("quick" ).with_scores ())
1044+ assert 0.23 == pytest .approx (res ["results" ][0 ]["score" ], 0.05 )
1045+ res = client .ft ().search (Query ("quick" ).scorer ("TFIDF" ).with_scores ())
1046+ assert 1.0 == res ["results" ][0 ]["score" ]
1047+ res = client .ft ().search (Query ("quick" ).scorer ("TFIDF.DOCNORM" ).with_scores ())
1048+ assert 0.14285714285714285 == res ["results" ][0 ]["score" ]
1049+ res = client .ft ().search (Query ("quick" ).scorer ("BM25" ).with_scores ())
1050+ assert 0.22471909420069797 == res ["results" ][0 ]["score" ]
1051+ res = client .ft ().search (Query ("quick" ).scorer ("DISMAX" ).with_scores ())
1052+ assert 2.0 == res ["results" ][0 ]["score" ]
1053+ res = client .ft ().search (Query ("quick" ).scorer ("DOCSCORE" ).with_scores ())
1054+ assert 1.0 == res ["results" ][0 ]["score" ]
1055+ res = client .ft ().search (Query ("quick" ).scorer ("HAMMING" ).with_scores ())
1056+ assert 0.0 == res ["results" ][0 ]["score" ]
1057+
1058+
9851059@pytest .mark .redismod
9861060def test_get (client ):
9871061 client .ft ().create_index ((TextField ("f1" ), TextField ("f2" )))
@@ -2605,9 +2679,8 @@ def test_search_missing_fields(client):
26052679 },
26062680 )
26072681
2608- with pytest .raises (redis .exceptions .ResponseError ) as e :
2682+ with pytest .raises (redis .exceptions .ResponseError ):
26092683 client .ft ().search (Query ("ismissing(@title)" ).return_field ("id" ).no_content ())
2610- assert "to be defined with 'INDEXMISSING'" in e .value .args [0 ]
26112684
26122685 res = client .ft ().search (
26132686 Query ("ismissing(@features)" ).return_field ("id" ).no_content ()
@@ -2813,6 +2886,12 @@ def test_search_query_with_different_dialects(client):
28132886 assert res ["total_results" ] == 0
28142887
28152888
2889+ @pytest .mark .redismod
2890+ @skip_if_server_version_lt ("7.9.0" )
2891+ def test_info_exposes_search_info (client ):
2892+ assert len (client .info ("search" )) > 0
2893+
2894+
28162895def _assert_search_result (client , result , expected_doc_ids ):
28172896 """
28182897 Make sure the result of a geo search is as expected, taking into account the RESP
0 commit comments