comparison scobot/index/access.py @ 16:7a87ba2f00d9

reformat, fix some types, make more async
author drewp@bigasterisk.com
date Fri, 19 Jul 2024 00:49:38 -0700
parents 6ed25bcaaf1f
children
comparison
equal deleted inserted replaced
15:6ed25bcaaf1f 16:7a87ba2f00d9
1 import logging
1 from pathlib import Path 2 from pathlib import Path
2 import shutil 3 import shutil
4 from typing import cast
3 5
4 from whoosh.index import create_in, open_dir 6 from whoosh.index import create_in, open_dir
5 7
6 from scobot.index.schema import schema 8 from scobot.index.schema import schema
7 9
8 log = None # set by flow 10 log = cast(logging.Logger, None) # set by flow
9 11
10 12
11 class SearchIndex: 13 class SearchIndex:
12 14
13 def __init__(self, indexDir: Path, delete_existing=True): 15 def __init__(self, indexDir: Path, delete_existing=True):
25 def commit(self): 27 def commit(self):
26 self.writer.commit() 28 self.writer.commit()
27 with self.ix.searcher() as searcher: 29 with self.ix.searcher() as searcher:
28 log.info(f'index doc count = {searcher.doc_count()}') 30 log.info(f'index doc count = {searcher.doc_count()}')
29 31
32
30 class SearchIndexRO: 33 class SearchIndexRO:
34
31 def __init__(self, indexDir: Path): 35 def __init__(self, indexDir: Path):
32 self.ix = open_dir(indexDir, readonly=True) 36 self.ix = open_dir(indexDir, readonly=True)
33 self.searcher = self.ix.searcher() 37 self.searcher = self.ix.searcher()
34 print(f'{self.searcher.doc_count()=}') 38 print(f'{self.searcher.doc_count()=}')