Add advanced search engine with inverted index, thread pool execution, configuration API, and comprehensive diagnostics
This commit is contained in:
@@ -22,6 +22,10 @@ vault_config: Dict[str, Dict[str, Any]] = {}
|
||||
# Thread-safe lock for index updates
|
||||
_index_lock = threading.Lock()
|
||||
|
||||
# Generation counter — incremented on each index rebuild so consumers
|
||||
# (e.g. the inverted index in search.py) can detect staleness.
|
||||
_index_generation: int = 0
|
||||
|
||||
# O(1) lookup table for wikilink resolution: {filename_lower: [{vault, path}, ...]}
|
||||
_file_lookup: Dict[str, List[Dict[str, str]]] = {}
|
||||
|
||||
@@ -318,6 +322,7 @@ async def build_index() -> None:
|
||||
new_path_index[vname] = vdata.get("paths", [])
|
||||
|
||||
# Atomic swap under lock for thread safety during concurrent reads
|
||||
global _index_generation
|
||||
with _index_lock:
|
||||
index.clear()
|
||||
index.update(new_index)
|
||||
@@ -325,6 +330,7 @@ async def build_index() -> None:
|
||||
_file_lookup.update(new_lookup)
|
||||
path_index.clear()
|
||||
path_index.update(new_path_index)
|
||||
_index_generation += 1
|
||||
|
||||
total_files = sum(len(v["files"]) for v in index.values())
|
||||
logger.info(f"Index built: {len(index)} vaults, {total_files} total files")
|
||||
|
||||
Reference in New Issue
Block a user