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

Method test_auto_complete

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

Source from the content-addressed store, hash-verified

567 @pytest.mark.redismod
568 @skip_if_redis_enterprise()
569 def test_auto_complete(self, client):
570 n = 0
571 with open(TITLES_CSV) as f:
572 cr = csv.reader(f)
573
574 for row in cr:
575 n += 1
576 term, score = row[0], float(row[1])
577 assert n == client.ft().sugadd("ac", Suggestion(term, score=score))
578
579 assert n == client.ft().suglen("ac")
580 ret = client.ft().sugget("ac", "bad", with_scores=True)
581 assert 2 == len(ret)
582 assert "badger" == ret[0].string
583 assert isinstance(ret[0].score, float)
584 assert 1.0 != ret[0].score
585 assert "badalte rishtey" == ret[1].string
586 assert isinstance(ret[1].score, float)
587 assert 1.0 != ret[1].score
588
589 ret = client.ft().sugget("ac", "bad", fuzzy=True, num=10)
590 assert 10 == len(ret)
591 assert 1.0 == ret[0].score
592 strs = {x.string for x in ret}
593
594 for sug in strs:
595 assert 1 == client.ft().sugdel("ac", sug)
596 # make sure a second delete returns 0
597 for sug in strs:
598 assert 0 == client.ft().sugdel("ac", sug)
599
600 # make sure they were actually deleted
601 ret2 = client.ft().sugget("ac", "bad", fuzzy=True, num=10)
602 for sug in ret2:
603 assert sug.string not in strs
604
605 # Test with payload
606 client.ft().sugadd("ac", Suggestion("pay1", payload="pl1"))
607 client.ft().sugadd("ac", Suggestion("pay2", payload="pl2"))
608 client.ft().sugadd("ac", Suggestion("pay3", payload="pl3"))
609
610 sugs = client.ft().sugget("ac", "pay", with_payloads=True, with_scores=True)
611 assert 3 == len(sugs)
612 for sug in sugs:
613 assert sug.payload
614 assert sug.payload.startswith("pl")
615
616 @pytest.mark.redismod
617 def test_no_index(self, client):

Callers

nothing calls this directly

Calls 6

SuggestionClass · 0.90
suglenMethod · 0.80
sugdelMethod · 0.80
sugaddMethod · 0.45
ftMethod · 0.45
suggetMethod · 0.45

Tested by

no test coverage detected