MCPcopy
hub / github.com/redis/redis-py / test_scorer

Method test_scorer

tests/test_search.py:1791–1839  ·  view source on GitHub ↗
(self, client)

Source from the content-addressed store, hash-verified

1789 @skip_ifmodversion_lt("2.8.0", "search")
1790 @skip_if_server_version_gte("7.9.0")
1791 def test_scorer(self, client):
1792 client.ft().create_index((TextField("description"),))
1793
1794 client.hset(
1795 "doc1",
1796 mapping={"description": "The quick brown fox jumps over the lazy dog"},
1797 )
1798 client.hset(
1799 "doc2",
1800 mapping={
1801 "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
1802 },
1803 )
1804
1805 # default scorer is TFIDF
1806 if expects_resp2_shape(client) or expects_unified_shape(client):
1807 res = client.ft().search(Query("quick").with_scores())
1808 assert 1.0 == res.docs[0].score
1809 res = client.ft().search(Query("quick").scorer("TFIDF").with_scores())
1810 assert 1.0 == res.docs[0].score
1811 res = client.ft().search(
1812 Query("quick").scorer("TFIDF.DOCNORM").with_scores()
1813 )
1814 assert 0.14285714285714285 == res.docs[0].score
1815 res = client.ft().search(Query("quick").scorer("BM25").with_scores())
1816 assert 0.22471909420069797 == res.docs[0].score
1817 res = client.ft().search(Query("quick").scorer("DISMAX").with_scores())
1818 assert 2.0 == res.docs[0].score
1819 res = client.ft().search(Query("quick").scorer("DOCSCORE").with_scores())
1820 assert 1.0 == res.docs[0].score
1821 res = client.ft().search(Query("quick").scorer("HAMMING").with_scores())
1822 assert 0.0 == res.docs[0].score
1823 elif expects_resp3_shape(client):
1824 res = client.ft().search(Query("quick").with_scores())
1825 assert 1.0 == res["results"][0]["score"]
1826 res = client.ft().search(Query("quick").scorer("TFIDF").with_scores())
1827 assert 1.0 == res["results"][0]["score"]
1828 res = client.ft().search(
1829 Query("quick").scorer("TFIDF.DOCNORM").with_scores()
1830 )
1831 assert 0.14285714285714285 == res["results"][0]["score"]
1832 res = client.ft().search(Query("quick").scorer("BM25").with_scores())
1833 assert 0.22471909420069797 == res["results"][0]["score"]
1834 res = client.ft().search(Query("quick").scorer("DISMAX").with_scores())
1835 assert 2.0 == res["results"][0]["score"]
1836 res = client.ft().search(Query("quick").scorer("DOCSCORE").with_scores())
1837 assert 1.0 == res["results"][0]["score"]
1838 res = client.ft().search(Query("quick").scorer("HAMMING").with_scores())
1839 assert 0.0 == res["results"][0]["score"]
1840
1841 @pytest.mark.redismod
1842 @pytest.mark.onlynoncluster

Callers

nothing calls this directly

Calls 11

TextFieldClass · 0.90
QueryClass · 0.90
expects_resp2_shapeFunction · 0.85
expects_unified_shapeFunction · 0.85
expects_resp3_shapeFunction · 0.85
create_indexMethod · 0.80
hsetMethod · 0.80
with_scoresMethod · 0.80
ftMethod · 0.45
searchMethod · 0.45
scorerMethod · 0.45

Tested by

no test coverage detected