@@ -202,16 +202,16 @@ async def test_client(decoded_r: redis.Redis):
202
202
# test slop and in order
203
203
assert 193 == (await decoded_r .ft ().search (Query ("henry king" ))).total
204
204
assert (
205
- 3
206
- == (
207
- await decoded_r .ft ().search (Query ("henry king" ).slop (0 ).in_order ())
208
- ).total
205
+ 3
206
+ == (
207
+ await decoded_r .ft ().search (Query ("henry king" ).slop (0 ).in_order ())
208
+ ).total
209
209
)
210
210
assert (
211
- 52
212
- == (
213
- await decoded_r .ft ().search (Query ("king henry" ).slop (0 ).in_order ())
214
- ).total
211
+ 52
212
+ == (
213
+ await decoded_r .ft ().search (Query ("king henry" ).slop (0 ).in_order ())
214
+ ).total
215
215
)
216
216
assert 53 == (await decoded_r .ft ().search (Query ("henry king" ).slop (0 ))).total
217
217
assert 167 == (await decoded_r .ft ().search (Query ("henry king" ).slop (100 ))).total
@@ -294,31 +294,31 @@ async def test_client(decoded_r: redis.Redis):
294
294
295
295
# test slop and in order
296
296
assert (
297
- 193 == (await decoded_r .ft ().search (Query ("henry king" )))["total_results" ]
297
+ 193 == (await decoded_r .ft ().search (Query ("henry king" )))["total_results" ]
298
298
)
299
299
assert (
300
- 3
301
- == (await decoded_r .ft ().search (Query ("henry king" ).slop (0 ).in_order ()))[
302
- "total_results"
303
- ]
300
+ 3
301
+ == (await decoded_r .ft ().search (Query ("henry king" ).slop (0 ).in_order ()))[
302
+ "total_results"
303
+ ]
304
304
)
305
305
assert (
306
- 52
307
- == (await decoded_r .ft ().search (Query ("king henry" ).slop (0 ).in_order ()))[
308
- "total_results"
309
- ]
306
+ 52
307
+ == (await decoded_r .ft ().search (Query ("king henry" ).slop (0 ).in_order ()))[
308
+ "total_results"
309
+ ]
310
310
)
311
311
assert (
312
- 53
313
- == (await decoded_r .ft ().search (Query ("henry king" ).slop (0 )))[
314
- "total_results"
315
- ]
312
+ 53
313
+ == (await decoded_r .ft ().search (Query ("henry king" ).slop (0 )))[
314
+ "total_results"
315
+ ]
316
316
)
317
317
assert (
318
- 167
319
- == (await decoded_r .ft ().search (Query ("henry king" ).slop (100 )))[
320
- "total_results"
321
- ]
318
+ 167
319
+ == (await decoded_r .ft ().search (Query ("henry king" ).slop (100 )))[
320
+ "total_results"
321
+ ]
322
322
)
323
323
324
324
# test delete document
@@ -669,33 +669,33 @@ async def test_summarize(decoded_r: redis.Redis):
669
669
doc = sorted ((await decoded_r .ft ().search (q )).docs )[0 ]
670
670
assert "<b>Henry</b> IV" == doc .play
671
671
assert (
672
- "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
673
- == doc .txt
672
+ "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
673
+ == doc .txt
674
674
)
675
675
676
676
q = Query ("king henry" ).paging (0 , 1 ).summarize ().highlight ()
677
677
678
678
doc = sorted ((await decoded_r .ft ().search (q )).docs )[0 ]
679
679
assert "<b>Henry</b> ... " == doc .play
680
680
assert (
681
- "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
682
- == doc .txt
681
+ "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
682
+ == doc .txt
683
683
)
684
684
else :
685
685
doc = sorted ((await decoded_r .ft ().search (q ))["results" ])[0 ]
686
686
assert "<b>Henry</b> IV" == doc ["extra_attributes" ]["play" ]
687
687
assert (
688
- "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
689
- == doc ["extra_attributes" ]["txt" ]
688
+ "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
689
+ == doc ["extra_attributes" ]["txt" ]
690
690
)
691
691
692
692
q = Query ("king henry" ).paging (0 , 1 ).summarize ().highlight ()
693
693
694
694
doc = sorted ((await decoded_r .ft ().search (q ))["results" ])[0 ]
695
695
assert "<b>Henry</b> ... " == doc ["extra_attributes" ]["play" ]
696
696
assert (
697
- "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
698
- == doc ["extra_attributes" ]["txt" ]
697
+ "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
698
+ == doc ["extra_attributes" ]["txt" ]
699
699
)
700
700
701
701
@@ -932,10 +932,10 @@ async def test_spell_check(decoded_r: redis.Redis):
932
932
res = await decoded_r .ft ().spellcheck ("lorm" , include = "dict" )
933
933
assert len (res ["lorm" ]) == 3
934
934
assert (
935
- res ["lorm" ][0 ]["suggestion" ],
936
- res ["lorm" ][1 ]["suggestion" ],
937
- res ["lorm" ][2 ]["suggestion" ],
938
- ) == ("lorem" , "lore" , "lorm" )
935
+ res ["lorm" ][0 ]["suggestion" ],
936
+ res ["lorm" ][1 ]["suggestion" ],
937
+ res ["lorm" ][2 ]["suggestion" ],
938
+ ) == ("lorem" , "lore" , "lorm" )
939
939
assert (res ["lorm" ][0 ]["score" ], res ["lorm" ][1 ]["score" ]) == ("0.5" , "0" )
940
940
941
941
# test spellcheck exclude
@@ -963,9 +963,9 @@ async def test_spell_check(decoded_r: redis.Redis):
963
963
assert "lore" in res ["results" ]["lorm" ][1 ].keys ()
964
964
assert "lorm" in res ["results" ]["lorm" ][2 ].keys ()
965
965
assert (
966
- res ["results" ]["lorm" ][0 ]["lorem" ],
967
- res ["results" ]["lorm" ][1 ]["lore" ],
968
- ) == (0.5 , 0 )
966
+ res ["results" ]["lorm" ][0 ]["lorem" ],
967
+ res ["results" ]["lorm" ][1 ]["lore" ],
968
+ ) == (0.5 , 0 )
969
969
970
970
# test spellcheck exclude
971
971
res = await decoded_r .ft ().spellcheck ("lorm" , exclude = "dict" )
@@ -1034,7 +1034,8 @@ async def test_scorer(decoded_r: redis.Redis):
1034
1034
await decoded_r .hset (
1035
1035
"doc2" ,
1036
1036
mapping = {
1037
- "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
1037
+ "description" : "Quick alice was beginning to get very tired of sitting by her quick sister on the bank, and of having nothing to do."
1038
+ # noqa
1038
1039
},
1039
1040
)
1040
1041
@@ -1098,12 +1099,12 @@ async def test_get(decoded_r: redis.Redis):
1098
1099
)
1099
1100
1100
1101
assert [
1101
- ["f1" , "some valid content dd2" , "f2" , "this is sample text f2" ]
1102
- ] == await decoded_r .ft ().get ("doc2" )
1102
+ ["f1" , "some valid content dd2" , "f2" , "this is sample text f2" ]
1103
+ ] == await decoded_r .ft ().get ("doc2" )
1103
1104
assert [
1104
- ["f1" , "some valid content dd1" , "f2" , "this is sample text f1" ],
1105
- ["f1" , "some valid content dd2" , "f2" , "this is sample text f2" ],
1106
- ] == await decoded_r .ft ().get ("doc1" , "doc2" )
1105
+ ["f1" , "some valid content dd1" , "f2" , "this is sample text f1" ],
1106
+ ["f1" , "some valid content dd2" , "f2" , "this is sample text f2" ],
1107
+ ] == await decoded_r .ft ().get ("doc1" , "doc2" )
1107
1108
1108
1109
1109
1110
@pytest .mark .redismod
@@ -1305,7 +1306,7 @@ async def test_aggregations_groupby(decoded_r: redis.Redis):
1305
1306
res = (await decoded_r .ft ().aggregate (req ))["results" ][0 ]
1306
1307
assert res ["extra_attributes" ]["parent" ] == "redis"
1307
1308
assert (
1308
- res ["extra_attributes" ]["__generated_aliascount_distincttitle" ] == "3"
1309
+ res ["extra_attributes" ]["__generated_aliascount_distincttitle" ] == "3"
1309
1310
)
1310
1311
1311
1312
req = (
@@ -1317,8 +1318,8 @@ async def test_aggregations_groupby(decoded_r: redis.Redis):
1317
1318
res = (await decoded_r .ft ().aggregate (req ))["results" ][0 ]
1318
1319
assert res ["extra_attributes" ]["parent" ] == "redis"
1319
1320
assert (
1320
- res ["extra_attributes" ]["__generated_aliascount_distinctishtitle" ]
1321
- == "3"
1321
+ res ["extra_attributes" ]["__generated_aliascount_distinctishtitle" ]
1322
+ == "3"
1322
1323
)
1323
1324
1324
1325
req = (
@@ -1370,8 +1371,8 @@ async def test_aggregations_groupby(decoded_r: redis.Redis):
1370
1371
res = (await decoded_r .ft ().aggregate (req ))["results" ][0 ]
1371
1372
assert res ["extra_attributes" ]["parent" ] == "redis"
1372
1373
assert (
1373
- res ["extra_attributes" ]["__generated_aliasstddevrandom_num" ]
1374
- == "3.60555127546"
1374
+ res ["extra_attributes" ]["__generated_aliasstddevrandom_num" ]
1375
+ == "3.60555127546"
1375
1376
)
1376
1377
1377
1378
req = (
@@ -1383,8 +1384,8 @@ async def test_aggregations_groupby(decoded_r: redis.Redis):
1383
1384
res = (await decoded_r .ft ().aggregate (req ))["results" ][0 ]
1384
1385
assert res ["extra_attributes" ]["parent" ] == "redis"
1385
1386
assert (
1386
- res ["extra_attributes" ]["__generated_aliasquantilerandom_num,0.5" ]
1387
- == "8"
1387
+ res ["extra_attributes" ]["__generated_aliasquantilerandom_num,0.5" ]
1388
+ == "8"
1388
1389
)
1389
1390
1390
1391
req = (
@@ -1530,6 +1531,23 @@ async def test_withsuffixtrie(decoded_r: redis.Redis):
1530
1531
assert "WITHSUFFIXTRIE" in info ["attributes" ][0 ]["flags" ]
1531
1532
1532
1533
1534
+ @pytest .mark .redismod
1535
+ @skip_ifmodversion_lt ("2.10.05" , "search" )
1536
+ async def test_aggregations_add_scores (decoded_r : redis .Redis ):
1537
+ assert await decoded_r .ft ().create_index (
1538
+ (TextField ("name" , sortable = True , weight = 5.0 ), NumericField ("age" , sortable = True ))
1539
+ )
1540
+
1541
+ assert await decoded_r .ft ().client .hset ("doc1" , mapping = {"name" : "bar" , "age" : "25" })
1542
+ assert await decoded_r .ft ().client .hset ("doc2" , mapping = {"name" : "foo" , "age" : "19" })
1543
+
1544
+ req = (aggregations .AggregateRequest ("*" ).add_scores ())
1545
+ res = await decoded_r .ft ().aggregate (req )
1546
+ assert len (res .rows ) == 2
1547
+ assert res .rows [0 ] == ["__score" , "0.2" ]
1548
+ assert res .rows [1 ] == ["__score" , "0.2" ]
1549
+
1550
+
1533
1551
@pytest .mark .redismod
1534
1552
@skip_if_redis_enterprise ()
1535
1553
async def test_search_commands_in_pipeline (decoded_r : redis .Redis ):
@@ -1554,9 +1572,9 @@ async def test_search_commands_in_pipeline(decoded_r: redis.Redis):
1554
1572
assert "doc2" == res [3 ]["results" ][1 ]["id" ]
1555
1573
assert res [3 ]["results" ][0 ]["payload" ] is None
1556
1574
assert (
1557
- res [3 ]["results" ][0 ]["extra_attributes" ]
1558
- == res [3 ]["results" ][1 ]["extra_attributes" ]
1559
- == {"txt" : "foo bar" }
1575
+ res [3 ]["results" ][0 ]["extra_attributes" ]
1576
+ == res [3 ]["results" ][1 ]["extra_attributes" ]
1577
+ == {"txt" : "foo bar" }
1560
1578
)
1561
1579
1562
1580
@@ -1615,5 +1633,5 @@ async def test_binary_and_text_fields(decoded_r: redis.Redis):
1615
1633
), "The vectors are not equal"
1616
1634
1617
1635
assert (
1618
- docs [0 ]["first_name" ] == mixed_data ["first_name" ]
1636
+ docs [0 ]["first_name" ] == mixed_data ["first_name" ]
1619
1637
), "The text field is not decoded correctly"
0 commit comments