(client, num_docs=100, definition=None)
| 128 | |
| 129 | @staticmethod |
| 130 | def createIndex(client, num_docs=100, definition=None): |
| 131 | try: |
| 132 | client.create_index( |
| 133 | ( |
| 134 | TextField("play", weight=5.0), |
| 135 | TextField("txt"), |
| 136 | NumericField("chapter"), |
| 137 | ), |
| 138 | definition=definition, |
| 139 | ) |
| 140 | except redis.ResponseError: |
| 141 | client.dropindex(delete_documents=True) |
| 142 | return SearchTestsBase.createIndex( |
| 143 | client, num_docs=num_docs, definition=definition |
| 144 | ) |
| 145 | |
| 146 | chapters = {} |
| 147 | bzfp = TextIOWrapper(bz2.BZ2File(WILL_PLAY_TEXT), encoding="utf8") |
| 148 | |
| 149 | r = csv.reader(bzfp, delimiter=";") |
| 150 | for n, line in enumerate(r): |
| 151 | play, chapter, _, text = line[1], line[2], line[4], line[5] |
| 152 | |
| 153 | key = f"{play}:{chapter}".lower() |
| 154 | d = chapters.setdefault(key, {}) |
| 155 | d["play"] = play |
| 156 | d["txt"] = d.get("txt", "") + " " + text |
| 157 | d["chapter"] = int(chapter or 0) |
| 158 | if len(chapters) == num_docs: |
| 159 | break |
| 160 | |
| 161 | indexer = client.batch_indexer(chunk_size=50) |
| 162 | assert isinstance(indexer, Search.BatchIndexer) |
| 163 | assert 50 == indexer.chunk_size |
| 164 | |
| 165 | for key, doc in chapters.items(): |
| 166 | indexer.client.client.hset(key, mapping=doc) |
| 167 | indexer.commit() |
| 168 | |
| 169 | @pytest.fixture |
| 170 | def client(self, request, stack_url): |
no test coverage detected