Mercurial > code > home > repos > sco-bot
view scobot/index/access.py @ 15:6ed25bcaaf1f
add prefect and rebuild flow to k8s
author | drewp@bigasterisk.com |
---|---|
date | Fri, 19 Jul 2024 00:30:47 -0700 |
parents | 403eff4a16c8 |
children | 7a87ba2f00d9 |
line wrap: on
line source
from pathlib import Path import shutil from whoosh.index import create_in, open_dir from scobot.index.schema import schema log = None # set by flow class SearchIndex: def __init__(self, indexDir: Path, delete_existing=True): if delete_existing: shutil.rmtree(indexDir, ignore_errors=True) indexDir.mkdir(parents=True, exist_ok=True) self.ix = create_in(indexDir, schema) else: self.ix = open_dir(indexDir) 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()}') class SearchIndexRO: def __init__(self, indexDir: Path): self.ix = open_dir(indexDir, readonly=True) self.searcher = self.ix.searcher() print(f'{self.searcher.doc_count()=}')