Skip to content

Commit

Permalink
Updated the test for nested boost query with score analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-au-922 committed Apr 24, 2024
1 parent b18377b commit a11b7d1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/tantivy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,12 @@ def test_boost_query(self, ram_index):
repr(boosted_query)
== """Query(Boost(query=Boost(query=TermQuery(Term(field=0, type=Str, "sea")), boost=0.1), boost=0.1))"""
)
result = index.searcher().search(boosted_query, 10)
for _score, _ in result.hits:
# the score should be very small, due to
# the unknown score of BM25, we can only check for the relative difference
assert _score == pytest.approx(0.01, rel = 1)


boosted_query = Query.boost_query(
query1, -0.1
Expand All @@ -945,7 +951,10 @@ def test_boost_query(self, ram_index):
# Even with a negative boost, the query should still match the document
assert len(result.hits) == 1
titles = set()
for _, doc_address in result.hits:
for _score, doc_address in result.hits:

# the score should be negative
assert _score < 0
titles.update(index.searcher().doc(doc_address)["title"])
assert titles == {"The Old Man and the Sea"}

Expand Down

0 comments on commit a11b7d1

Please sign in to comment.