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

Method test_scorer

tests/test_asyncio/test_search.py:1205–1273  ·  view source on GitHub ↗
(self, decoded_r: redis.Redis)

Source from the content-addressed store, hash-verified

1203 @skip_ifmodversion_lt("2.8.0", "search")
1204 @skip_if_server_version_gte("7.9.0")
1205 async def test_scorer(self, decoded_r: redis.Redis):
1206 await decoded_r.ft().create_index((TextField("description"),))
1207
1208 await decoded_r.hset(
1209 "doc1",
1210 mapping={"description": "The quick brown fox jumps over the lazy dog"},
1211 )
1212 await decoded_r.hset(
1213 "doc2",
1214 mapping={
1215 "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
1216 },
1217 )
1218
1219 if expects_resp2_shape(decoded_r) or expects_unified_shape(decoded_r):
1220 # default scorer is TFIDF
1221 res = await decoded_r.ft().search(Query("quick").with_scores())
1222 assert 1.0 == res.docs[0].score
1223 res = await decoded_r.ft().search(
1224 Query("quick").scorer("TFIDF").with_scores()
1225 )
1226 assert 1.0 == res.docs[0].score
1227 res = await decoded_r.ft().search(
1228 Query("quick").scorer("TFIDF.DOCNORM").with_scores()
1229 )
1230 assert 0.14285714285714285 == res.docs[0].score
1231 res = await decoded_r.ft().search(
1232 Query("quick").scorer("BM25").with_scores()
1233 )
1234 assert 0.22471909420069797 == res.docs[0].score
1235 res = await decoded_r.ft().search(
1236 Query("quick").scorer("DISMAX").with_scores()
1237 )
1238 assert 2.0 == res.docs[0].score
1239 res = await decoded_r.ft().search(
1240 Query("quick").scorer("DOCSCORE").with_scores()
1241 )
1242 assert 1.0 == res.docs[0].score
1243 res = await decoded_r.ft().search(
1244 Query("quick").scorer("HAMMING").with_scores()
1245 )
1246 assert 0.0 == res.docs[0].score
1247 elif expects_resp3_shape(decoded_r):
1248 res = await decoded_r.ft().search(Query("quick").with_scores())
1249 assert 1.0 == res["results"][0]["score"]
1250 res = await decoded_r.ft().search(
1251 Query("quick").scorer("TFIDF").with_scores()
1252 )
1253 assert 1.0 == res["results"][0]["score"]
1254 res = await decoded_r.ft().search(
1255 Query("quick").scorer("TFIDF.DOCNORM").with_scores()
1256 )
1257 assert 0.14285714285714285 == res["results"][0]["score"]
1258 res = await decoded_r.ft().search(
1259 Query("quick").scorer("BM25").with_scores()
1260 )
1261 assert 0.22471909420069797 == res["results"][0]["score"]
1262 res = await decoded_r.ft().search(

Callers

nothing calls this directly

Calls 11

TextFieldClass · 0.90
expects_resp2_shapeFunction · 0.90
expects_unified_shapeFunction · 0.90
QueryClass · 0.90
expects_resp3_shapeFunction · 0.90
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