From 28b643e3f9a9be94e8d2c6076c525519c59c60c1 Mon Sep 17 00:00:00 2001 From: Adam Weidner Date: Mon, 26 Aug 2024 07:30:24 -0400 Subject: [PATCH] parameterizes test and fixes yaml lint error --- datasets/small_movies.json | 2 +- tests/index/test_index_search_meilisearch.py | 27 ++++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/datasets/small_movies.json b/datasets/small_movies.json index 86942b5b..04fc0179 100644 --- a/datasets/small_movies.json +++ b/datasets/small_movies.json @@ -227,4 +227,4 @@ "release_date": 1114669984, "genre": "Sci Fi" } -] +] \ No newline at end of file diff --git a/tests/index/test_index_search_meilisearch.py b/tests/index/test_index_search_meilisearch.py index 3a6457cd..ddf56e60 100644 --- a/tests/index/test_index_search_meilisearch.py +++ b/tests/index/test_index_search_meilisearch.py @@ -520,16 +520,17 @@ def test_search_distinct(index_with_documents): assert response["hits"][0]["id"] == "399579" -def test_search_ranking_threshold(index_with_documents): - # No documents matched with exact phrase and ranking threshold 1 - response = index_with_documents().search("Husband and wife", {"rankingScoreThreshold": 1}) - assert len(response["hits"]) == 0 - # Only one document contains this phrase - response = index_with_documents().search("Husband and wife", {"rankingScoreThreshold": 0.9}) - assert len(response["hits"]) == 1 - # No documents matched with too high of a threshold for this term - response = index_with_documents().search("wife", {"rankingScoreThreshold": 0.9}) - assert len(response["hits"]) == 0 - # Two documents do contain the term but they only match at a lower threshold - response = index_with_documents().search("wife", {"rankingScoreThreshold": 0.5}) - assert len(response["hits"]) == 2 +@pytest.mark.parametrize( + "query, ranking_score_threshold, expected", + ( + ("Husband and wife", 1, 0), + ("Husband and wife", 0.9, 1), + ("wife", 0.9, 0), + ("wife", 0.5, 2), + ), +) +def test_search_ranking_threshold(query, ranking_score_threshold, expected, index_with_documents): + response = index_with_documents().search( + query, {"rankingScoreThreshold": ranking_score_threshold} + ) + assert len(response["hits"]) == expected