@@ -175,6 +175,10 @@ def test_raises_value_error_if_wrong_sort_order(self):
175
175
with pytest .raises (ValueError ):
176
176
MetaFieldRanker (meta_field = "rating" , sort_order = "wrong_order" )
177
177
178
+ def test_raises_value_error_if_wrong_missing_meta (self ):
179
+ with pytest .raises (ValueError ):
180
+ MetaFieldRanker (meta_field = "rating" , missing_meta = "wrong_missing_meta" )
181
+
178
182
def test_raises_value_error_if_wrong_meta_value_type (self ):
179
183
with pytest .raises (ValueError ):
180
184
MetaFieldRanker (meta_field = "rating" , meta_value_type = "wrong_type" )
@@ -239,3 +243,39 @@ def test_different_ranking_mode_for_init_vs_run(self):
239
243
output = ranker .run (documents = docs_before , ranking_mode = "reciprocal_rank_fusion" )
240
244
docs_after = output ["documents" ]
241
245
assert docs_after [0 ].score == pytest .approx (0.016261 , abs = 1e-5 )
246
+
247
+ def test_missing_meta_bottom (self ):
248
+ ranker = MetaFieldRanker (meta_field = "rating" , ranking_mode = "linear_score" , weight = 0.5 , missing_meta = "bottom" )
249
+ docs_before = [
250
+ Document (id = "1" , content = "abc" , meta = {"rating" : 1.3 }, score = 0.6 ),
251
+ Document (id = "2" , content = "abc" , meta = {}, score = 0.4 ),
252
+ Document (id = "3" , content = "abc" , meta = {"rating" : 2.1 }, score = 0.39 ),
253
+ ]
254
+ output = ranker .run (documents = docs_before )
255
+ docs_after = output ["documents" ]
256
+ assert len (docs_after ) == 3
257
+ assert docs_after [2 ].id == "2"
258
+
259
+ def test_missing_meta_top (self ):
260
+ ranker = MetaFieldRanker (meta_field = "rating" , ranking_mode = "linear_score" , weight = 0.5 , missing_meta = "top" )
261
+ docs_before = [
262
+ Document (id = "1" , content = "abc" , meta = {"rating" : 1.3 }, score = 0.6 ),
263
+ Document (id = "2" , content = "abc" , meta = {}, score = 0.59 ),
264
+ Document (id = "3" , content = "abc" , meta = {"rating" : 2.1 }, score = 0.4 ),
265
+ ]
266
+ output = ranker .run (documents = docs_before )
267
+ docs_after = output ["documents" ]
268
+ assert len (docs_after ) == 3
269
+ assert docs_after [0 ].id == "2"
270
+
271
+ def test_missing_meta_drop (self ):
272
+ ranker = MetaFieldRanker (meta_field = "rating" , ranking_mode = "linear_score" , weight = 0.5 , missing_meta = "drop" )
273
+ docs_before = [
274
+ Document (id = "1" , content = "abc" , meta = {"rating" : 1.3 }, score = 0.6 ),
275
+ Document (id = "2" , content = "abc" , meta = {}, score = 0.59 ),
276
+ Document (id = "3" , content = "abc" , meta = {"rating" : 2.1 }, score = 0.4 ),
277
+ ]
278
+ output = ranker .run (documents = docs_before )
279
+ docs_after = output ["documents" ]
280
+ assert len (docs_after ) == 2
281
+ assert "2" not in [doc .id for doc in docs_after ]
0 commit comments