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

Method test_summarize

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

Source from the content-addressed store, hash-verified

715
716 @pytest.mark.redismod
717 def test_summarize(self, client):
718 self.createIndex(client.ft())
719 self.waitForIndex(client, getattr(client.ft(), "index_name", "idx"))
720
721 q = Query('"king henry"').paging(0, 1)
722 q.highlight(fields=("play", "txt"), tags=("<b>", "</b>"))
723 q.summarize("txt")
724
725 if expects_resp2_shape(client) or expects_unified_shape(client):
726 doc = sorted(client.ft().search(q).docs)[0]
727 assert "<b>Henry</b> IV" == doc.play
728 assert (
729 "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
730 == doc.txt
731 )
732
733 q = Query('"king henry"').paging(0, 1).summarize().highlight()
734
735 doc = sorted(client.ft().search(q).docs)[0]
736 assert "<b>Henry</b> ... " == doc.play
737 assert (
738 "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
739 == doc.txt
740 )
741 elif expects_resp3_shape(client):
742 doc = sorted(client.ft().search(q)["results"])[0]
743 assert "<b>Henry</b> IV" == doc["extra_attributes"]["play"]
744 assert (
745 "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
746 == doc["extra_attributes"]["txt"]
747 )
748
749 q = Query('"king henry"').paging(0, 1).summarize().highlight()
750
751 doc = sorted(client.ft().search(q)["results"])[0]
752 assert "<b>Henry</b> ... " == doc["extra_attributes"]["play"]
753 assert (
754 "ACT I SCENE I. London. The palace. Enter <b>KING</b> <b>HENRY</b>, LORD JOHN OF LANCASTER, the EARL of WESTMORELAND, SIR... " # noqa
755 == doc["extra_attributes"]["txt"]
756 )
757
758 @pytest.mark.redismod
759 @skip_ifmodversion_lt("2.0.0", "search")

Callers

nothing calls this directly

Calls 11

QueryClass · 0.90
expects_resp2_shapeFunction · 0.85
expects_unified_shapeFunction · 0.85
expects_resp3_shapeFunction · 0.85
pagingMethod · 0.80
highlightMethod · 0.80
summarizeMethod · 0.80
createIndexMethod · 0.45
ftMethod · 0.45
waitForIndexMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected