@@ -61,9 +61,7 @@ def getClient():
61
61
def createIndex (client , num_docs = 100 , definition = None ):
62
62
try :
63
63
client .create_index (
64
- (TextField ("play" , weight = 5.0 ),
65
- TextField ("txt" ),
66
- NumericField ("chapter" )),
64
+ (TextField ("play" , weight = 5.0 ), TextField ("txt" ), NumericField ("chapter" )),
67
65
definition = definition ,
68
66
)
69
67
except redis .ResponseError :
@@ -286,17 +284,8 @@ def test_stopwords(client):
286
284
287
285
@pytest .mark .redismod
288
286
def test_filters (client ):
289
- client .ft ().create_index (
290
- (TextField ("txt" ),
291
- NumericField ("num" ),
292
- GeoField ("loc" ))
293
- )
294
- client .ft ().add_document (
295
- "doc1" ,
296
- txt = "foo bar" ,
297
- num = 3.141 ,
298
- loc = "-0.441,51.458"
299
- )
287
+ client .ft ().create_index ((TextField ("txt" ), NumericField ("num" ), GeoField ("loc" )))
288
+ client .ft ().add_document ("doc1" , txt = "foo bar" , num = 3.141 , loc = "-0.441,51.458" )
300
289
client .ft ().add_document ("doc2" , txt = "foo baz" , num = 2 , loc = "-0.1,51.2" )
301
290
302
291
waitForIndex (client , "idx" )
@@ -342,10 +331,7 @@ def test_payloads_with_no_content(client):
342
331
343
332
@pytest .mark .redismod
344
333
def test_sort_by (client ):
345
- client .ft ().create_index (
346
- (TextField ("txt" ),
347
- NumericField ("num" , sortable = True ))
348
- )
334
+ client .ft ().create_index ((TextField ("txt" ), NumericField ("num" , sortable = True )))
349
335
client .ft ().add_document ("doc1" , txt = "foo bar" , num = 1 )
350
336
client .ft ().add_document ("doc2" , txt = "foo baz" , num = 2 )
351
337
client .ft ().add_document ("doc3" , txt = "foo qux" , num = 3 )
@@ -387,10 +373,7 @@ def test_drop_index():
387
373
@pytest .mark .redismod
388
374
def test_example (client ):
389
375
# Creating the index definition and schema
390
- client .ft ().create_index (
391
- (TextField ("title" , weight = 5.0 ),
392
- TextField ("body" ))
393
- )
376
+ client .ft ().create_index ((TextField ("title" , weight = 5.0 ), TextField ("body" )))
394
377
395
378
# Indexing a document
396
379
client .ft ().add_document (
@@ -510,11 +493,7 @@ def test_no_index(client):
510
493
511
494
@pytest .mark .redismod
512
495
def test_partial (client ):
513
- client .ft ().create_index (
514
- (TextField ("f1" ),
515
- TextField ("f2" ),
516
- TextField ("f3" ))
517
- )
496
+ client .ft ().create_index ((TextField ("f1" ), TextField ("f2" ), TextField ("f3" )))
518
497
client .ft ().add_document ("doc1" , f1 = "f1_val" , f2 = "f2_val" )
519
498
client .ft ().add_document ("doc2" , f1 = "f1_val" , f2 = "f2_val" )
520
499
client .ft ().add_document ("doc1" , f3 = "f3_val" , partial = True )
@@ -532,11 +511,7 @@ def test_partial(client):
532
511
533
512
@pytest .mark .redismod
534
513
def test_no_create (client ):
535
- client .ft ().create_index (
536
- (TextField ("f1" ),
537
- TextField ("f2" ),
538
- TextField ("f3" ))
539
- )
514
+ client .ft ().create_index ((TextField ("f1" ), TextField ("f2" ), TextField ("f3" )))
540
515
client .ft ().add_document ("doc1" , f1 = "f1_val" , f2 = "f2_val" )
541
516
client .ft ().add_document ("doc2" , f1 = "f1_val" , f2 = "f2_val" )
542
517
client .ft ().add_document ("doc1" , f3 = "f3_val" , no_create = True )
@@ -557,11 +532,7 @@ def test_no_create(client):
557
532
558
533
@pytest .mark .redismod
559
534
def test_explain (client ):
560
- client .ft ().create_index (
561
- (TextField ("f1" ),
562
- TextField ("f2" ),
563
- TextField ("f3" ))
564
- )
535
+ client .ft ().create_index ((TextField ("f1" ), TextField ("f2" ), TextField ("f3" )))
565
536
res = client .ft ().explain ("@f3:f3_val @f2:f2_val @f1:f1_val" )
566
537
assert res
567
538
@@ -584,17 +555,17 @@ def test_summarize(client):
584
555
doc = sorted (client .ft ().search (q ).docs )[0 ]
585
556
assert "<b>Henry</b> IV" == doc .play
586
557
assert (
587
- "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
588
- == doc .txt
558
+ "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
559
+ == doc .txt
589
560
)
590
561
591
562
q = Query ("king henry" ).paging (0 , 1 ).summarize ().highlight ()
592
563
593
564
doc = sorted (client .ft ().search (q ).docs )[0 ]
594
565
assert "<b>Henry</b> ... " == doc .play
595
566
assert (
596
- "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
597
- == doc .txt
567
+ "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
568
+ == doc .txt
598
569
)
599
570
600
571
@@ -763,10 +734,10 @@ def test_spell_check(client):
763
734
res = client .ft ().spellcheck ("lorm" , include = "dict" )
764
735
assert len (res ["lorm" ]) == 3
765
736
assert (
766
- res ["lorm" ][0 ]["suggestion" ],
767
- res ["lorm" ][1 ]["suggestion" ],
768
- res ["lorm" ][2 ]["suggestion" ],
769
- ) == ("lorem" , "lore" , "lorm" )
737
+ res ["lorm" ][0 ]["suggestion" ],
738
+ res ["lorm" ][1 ]["suggestion" ],
739
+ res ["lorm" ][2 ]["suggestion" ],
740
+ ) == ("lorem" , "lore" , "lorm" )
770
741
assert (res ["lorm" ][0 ]["score" ], res ["lorm" ][1 ]["score" ]) == ("0.5" , "0" )
771
742
772
743
# test spellcheck exclude
@@ -1010,7 +981,7 @@ def test_aggregations_groupby(client):
1010
981
)
1011
982
1012
983
res = client .ft ().aggregate (req ).rows [0 ]
1013
- assert res == [' parent' , ' redis' , ' first' , ' RediSearch' ]
984
+ assert res == [" parent" , " redis" , " first" , " RediSearch" ]
1014
985
1015
986
req = aggregations .AggregateRequest ("redis" ).group_by (
1016
987
"@parent" ,
@@ -1033,35 +1004,33 @@ def test_aggregations_sort_by_and_limit(client):
1033
1004
)
1034
1005
)
1035
1006
1036
- client .ft ().client .hset ("doc1" , mapping = {'t1' : 'a' , 't2' : 'b' })
1037
- client .ft ().client .hset ("doc2" , mapping = {'t1' : 'b' , 't2' : 'a' })
1007
+ client .ft ().client .hset ("doc1" , mapping = {"t1" : "a" , "t2" : "b" })
1008
+ client .ft ().client .hset ("doc2" , mapping = {"t1" : "b" , "t2" : "a" })
1038
1009
1039
1010
# test sort_by using SortDirection
1040
- req = aggregations .AggregateRequest ("*" ) \
1041
- .sort_by (aggregations .Asc ("@t2" ), aggregations .Desc ("@t1" ))
1011
+ req = aggregations .AggregateRequest ("*" ).sort_by (
1012
+ aggregations .Asc ("@t2" ), aggregations .Desc ("@t1" )
1013
+ )
1042
1014
res = client .ft ().aggregate (req )
1043
- assert res .rows [0 ] == ['t2' , 'a' , 't1' , 'b' ]
1044
- assert res .rows [1 ] == ['t2' , 'b' , 't1' , 'a' ]
1015
+ assert res .rows [0 ] == ["t2" , "a" , "t1" , "b" ]
1016
+ assert res .rows [1 ] == ["t2" , "b" , "t1" , "a" ]
1045
1017
1046
1018
# test sort_by without SortDirection
1047
- req = aggregations .AggregateRequest ("*" ) \
1048
- .sort_by ("@t1" )
1019
+ req = aggregations .AggregateRequest ("*" ).sort_by ("@t1" )
1049
1020
res = client .ft ().aggregate (req )
1050
- assert res .rows [0 ] == ['t1' , 'a' ]
1051
- assert res .rows [1 ] == ['t1' , 'b' ]
1021
+ assert res .rows [0 ] == ["t1" , "a" ]
1022
+ assert res .rows [1 ] == ["t1" , "b" ]
1052
1023
1053
1024
# test sort_by with max
1054
- req = aggregations .AggregateRequest ("*" ) \
1055
- .sort_by ("@t1" , max = 1 )
1025
+ req = aggregations .AggregateRequest ("*" ).sort_by ("@t1" , max = 1 )
1056
1026
res = client .ft ().aggregate (req )
1057
1027
assert len (res .rows ) == 1
1058
1028
1059
1029
# test limit
1060
- req = aggregations .AggregateRequest ("*" ) \
1061
- .sort_by ("@t1" ).limit (1 , 1 )
1030
+ req = aggregations .AggregateRequest ("*" ).sort_by ("@t1" ).limit (1 , 1 )
1062
1031
res = client .ft ().aggregate (req )
1063
1032
assert len (res .rows ) == 1
1064
- assert res .rows [0 ] == ['t1' , 'b' ]
1033
+ assert res .rows [0 ] == ["t1" , "b" ]
1065
1034
1066
1035
1067
1036
@pytest .mark .redismod
@@ -1073,22 +1042,22 @@ def test_aggregations_load(client):
1073
1042
)
1074
1043
)
1075
1044
1076
- client .ft ().client .hset ("doc1" , mapping = {'t1' : ' hello' , 't2' : ' world' })
1045
+ client .ft ().client .hset ("doc1" , mapping = {"t1" : " hello" , "t2" : " world" })
1077
1046
1078
1047
# load t1
1079
1048
req = aggregations .AggregateRequest ("*" ).load ("t1" )
1080
1049
res = client .ft ().aggregate (req )
1081
- assert res .rows [0 ] == ['t1' , ' hello' ]
1050
+ assert res .rows [0 ] == ["t1" , " hello" ]
1082
1051
1083
1052
# load t2
1084
1053
req = aggregations .AggregateRequest ("*" ).load ("t2" )
1085
1054
res = client .ft ().aggregate (req )
1086
- assert res .rows [0 ] == ['t2' , ' world' ]
1055
+ assert res .rows [0 ] == ["t2" , " world" ]
1087
1056
1088
1057
# load all
1089
1058
req = aggregations .AggregateRequest ("*" ).load ()
1090
1059
res = client .ft ().aggregate (req )
1091
- assert res .rows [0 ] == ['t1' , ' hello' , 't2' , ' world' ]
1060
+ assert res .rows [0 ] == ["t1" , " hello" , "t2" , " world" ]
1092
1061
1093
1062
1094
1063
@pytest .mark .redismod
@@ -1102,24 +1071,19 @@ def test_aggregations_apply(client):
1102
1071
1103
1072
client .ft ().client .hset (
1104
1073
"doc1" ,
1105
- mapping = {
1106
- 'PrimaryKey' : '9::362330' ,
1107
- 'CreatedDateTimeUTC' : '637387878524969984'
1108
- }
1074
+ mapping = {"PrimaryKey" : "9::362330" , "CreatedDateTimeUTC" : "637387878524969984" },
1109
1075
)
1110
1076
client .ft ().client .hset (
1111
1077
"doc2" ,
1112
- mapping = {
1113
- 'PrimaryKey' : '9::362329' ,
1114
- 'CreatedDateTimeUTC' : '637387875859270016'
1115
- }
1078
+ mapping = {"PrimaryKey" : "9::362329" , "CreatedDateTimeUTC" : "637387875859270016" },
1116
1079
)
1117
1080
1118
- req = aggregations .AggregateRequest ("*" ) \
1119
- .apply (CreatedDateTimeUTC = '@CreatedDateTimeUTC * 10' )
1081
+ req = aggregations .AggregateRequest ("*" ).apply (
1082
+ CreatedDateTimeUTC = "@CreatedDateTimeUTC * 10"
1083
+ )
1120
1084
res = client .ft ().aggregate (req )
1121
- assert res .rows [0 ] == [' CreatedDateTimeUTC' , ' 6373878785249699840' ]
1122
- assert res .rows [1 ] == [' CreatedDateTimeUTC' , ' 6373878758592700416' ]
1085
+ assert res .rows [0 ] == [" CreatedDateTimeUTC" , " 6373878785249699840" ]
1086
+ assert res .rows [1 ] == [" CreatedDateTimeUTC" , " 6373878758592700416" ]
1123
1087
1124
1088
1125
1089
@pytest .mark .redismod
@@ -1131,33 +1095,19 @@ def test_aggregations_filter(client):
1131
1095
)
1132
1096
)
1133
1097
1134
- client .ft ().client .hset (
1135
- "doc1" ,
1136
- mapping = {
1137
- 'name' : 'bar' ,
1138
- 'age' : '25'
1139
- }
1140
- )
1141
- client .ft ().client .hset (
1142
- "doc2" ,
1143
- mapping = {
1144
- 'name' : 'foo' ,
1145
- 'age' : '19'
1146
- }
1147
- )
1098
+ client .ft ().client .hset ("doc1" , mapping = {"name" : "bar" , "age" : "25" })
1099
+ client .ft ().client .hset ("doc2" , mapping = {"name" : "foo" , "age" : "19" })
1148
1100
1149
- req = aggregations .AggregateRequest ("*" ) \
1150
- .filter ("@name=='foo' && @age < 20" )
1101
+ req = aggregations .AggregateRequest ("*" ).filter ("@name=='foo' && @age < 20" )
1151
1102
res = client .ft ().aggregate (req )
1152
1103
assert len (res .rows ) == 1
1153
- assert res .rows [0 ] == [' name' , ' foo' , ' age' , '19' ]
1104
+ assert res .rows [0 ] == [" name" , " foo" , " age" , "19" ]
1154
1105
1155
- req = aggregations .AggregateRequest ("*" ) \
1156
- .filter ("@age > 15" ).sort_by ("@age" )
1106
+ req = aggregations .AggregateRequest ("*" ).filter ("@age > 15" ).sort_by ("@age" )
1157
1107
res = client .ft ().aggregate (req )
1158
1108
assert len (res .rows ) == 2
1159
- assert res .rows [0 ] == [' age' , '19' ]
1160
- assert res .rows [1 ] == [' age' , '25' ]
1109
+ assert res .rows [0 ] == [" age" , "19" ]
1110
+ assert res .rows [1 ] == [" age" , "25" ]
1161
1111
1162
1112
1163
1113
@pytest .mark .redismod
@@ -1181,25 +1131,25 @@ def test_index_definition(client):
1181
1131
)
1182
1132
1183
1133
assert [
1184
- "ON" ,
1185
- "JSON" ,
1186
- "PREFIX" ,
1187
- 2 ,
1188
- "hset:" ,
1189
- "henry" ,
1190
- "FILTER" ,
1191
- "@f1==32" ,
1192
- "LANGUAGE_FIELD" ,
1193
- "play" ,
1194
- "LANGUAGE" ,
1195
- "English" ,
1196
- "SCORE_FIELD" ,
1197
- "chapter" ,
1198
- "SCORE" ,
1199
- 0.5 ,
1200
- "PAYLOAD_FIELD" ,
1201
- "txt" ,
1202
- ] == definition .args
1134
+ "ON" ,
1135
+ "JSON" ,
1136
+ "PREFIX" ,
1137
+ 2 ,
1138
+ "hset:" ,
1139
+ "henry" ,
1140
+ "FILTER" ,
1141
+ "@f1==32" ,
1142
+ "LANGUAGE_FIELD" ,
1143
+ "play" ,
1144
+ "LANGUAGE" ,
1145
+ "English" ,
1146
+ "SCORE_FIELD" ,
1147
+ "chapter" ,
1148
+ "SCORE" ,
1149
+ 0.5 ,
1150
+ "PAYLOAD_FIELD" ,
1151
+ "txt" ,
1152
+ ] == definition .args
1203
1153
1204
1154
createIndex (client .ft (), num_docs = 500 , definition = definition )
1205
1155
0 commit comments