Mercurial > code > home > repos > sco-bot
comparison scobot/index/access.py @ 11:6622bacb0b84
first pass at reorg
author | drewp@bigasterisk.com |
---|---|
date | Thu, 11 Jul 2024 18:15:44 -0700 |
parents | flow/search_index.py@13438795d896 |
children | 403eff4a16c8 |
comparison
equal
deleted
inserted
replaced
10:13438795d896 | 11:6622bacb0b84 |
---|---|
1 from pathlib import Path | |
2 | |
3 from whoosh.index import create_in | |
4 | |
5 from scobot.index.schema import schema | |
6 | |
7 log = None # set by flow | |
8 | |
9 | |
10 class SearchIndex: | |
11 | |
12 def __init__(self, indexDir: Path): | |
13 indexDir.mkdir(parents=True, exist_ok=True) | |
14 self.ix = create_in(indexDir, schema) | |
15 self.writer = self.ix.writer() | |
16 | |
17 def addDoc(self, **kw): | |
18 self.writer.add_document(**kw) | |
19 | |
20 def commit(self): | |
21 self.writer.commit() | |
22 with self.ix.searcher() as searcher: | |
23 log.info(f'index doc count = {searcher.doc_count()}') |