Mercurial > code > home > repos > sco-bot
comparison flow/search_index.py @ 10:13438795d896
rewrite with prefect flows and whoosh search, but it's in a nested pdm env
author | drewp@bigasterisk.com |
---|---|
date | Thu, 11 Jul 2024 17:35:31 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:d1b54241a731 | 10:13438795d896 |
---|---|
1 from pathlib import Path | |
2 | |
3 from whoosh.fields import ID | |
4 from whoosh.index import create_in | |
5 | |
6 from schema import schema | |
7 | |
8 log = None # set by flow | |
9 | |
10 | |
11 class SearchIndex: | |
12 | |
13 def __init__(self, indexDir: Path): | |
14 indexDir.mkdir(parents=True, exist_ok=True) | |
15 self.ix = create_in(indexDir, schema) | |
16 self.writer = self.ix.writer() | |
17 | |
18 def addDoc(self, **kw): | |
19 self.writer.add_document(**kw) | |
20 | |
21 def commit(self): | |
22 self.writer.commit() | |
23 with self.ix.searcher() as searcher: | |
24 log.info(f'index doc count = {searcher.doc_count()}') |