(decoded_r, num_docs=100, definition=None)
| 99 | |
| 100 | @staticmethod |
| 101 | async def createIndex(decoded_r, num_docs=100, definition=None): |
| 102 | try: |
| 103 | await decoded_r.create_index( |
| 104 | ( |
| 105 | TextField("play", weight=5.0), |
| 106 | TextField("txt"), |
| 107 | NumericField("chapter"), |
| 108 | ), |
| 109 | definition=definition, |
| 110 | ) |
| 111 | except redis.ResponseError: |
| 112 | await decoded_r.dropindex(delete_documents=True) |
| 113 | return await AsyncSearchTestsBase.createIndex( |
| 114 | decoded_r, num_docs=num_docs, definition=definition |
| 115 | ) |
| 116 | |
| 117 | chapters = {} |
| 118 | bzfp = TextIOWrapper(bz2.BZ2File(WILL_PLAY_TEXT), encoding="utf8") |
| 119 | |
| 120 | r = csv.reader(bzfp, delimiter=";") |
| 121 | for n, line in enumerate(r): |
| 122 | play, chapter, _, text = line[1], line[2], line[4], line[5] |
| 123 | |
| 124 | key = f"{play}:{chapter}".lower() |
| 125 | d = chapters.setdefault(key, {}) |
| 126 | d["play"] = play |
| 127 | d["txt"] = d.get("txt", "") + " " + text |
| 128 | d["chapter"] = int(chapter or 0) |
| 129 | if len(chapters) == num_docs: |
| 130 | break |
| 131 | |
| 132 | indexer = decoded_r.batch_indexer(chunk_size=50) |
| 133 | assert isinstance(indexer, AsyncSearch.BatchIndexer) |
| 134 | assert 50 == indexer.chunk_size |
| 135 | |
| 136 | for key, doc in chapters.items(): |
| 137 | await indexer.client.client.hset(key, mapping=doc) |
| 138 | await indexer.commit() |
| 139 | |
| 140 | |
| 141 | class TestBaseSearchFunctionality(AsyncSearchTestsBase): |
no test coverage detected