Mercurial > code > home > repos > sco-bot
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scobot/index/access.py Thu Jul 11 18:15:44 2024 -0700 @@ -0,0 +1,23 @@ +from pathlib import Path + +from whoosh.index import create_in + +from scobot.index.schema import schema + +log = None # set by flow + + +class SearchIndex: + + def __init__(self, indexDir: Path): + indexDir.mkdir(parents=True, exist_ok=True) + self.ix = create_in(indexDir, schema) + self.writer = self.ix.writer() + + def addDoc(self, **kw): + self.writer.add_document(**kw) + + def commit(self): + self.writer.commit() + with self.ix.searcher() as searcher: + log.info(f'index doc count = {searcher.doc_count()}')