diff --git a/backend/indexer.py b/backend/indexer.py index 806d637..d2c4217 100644 --- a/backend/indexer.py +++ b/backend/indexer.py @@ -27,6 +27,19 @@ _async_index_lock: asyncio.Lock = None # initialized lazily # (e.g. the inverted index in search.py) can detect staleness. _index_generation: int = 0 +# Hook for incremental inverted index updates: called as (action, vault, path, file_info) +_on_index_change: callable = None + + +def set_index_change_hook(hook): + """Register a callback for incremental inverted index updates. + + The hook is called as ``hook(action, vault_name, path, file_info)`` + where ``action`` is ``'add'`` or ``'remove'``. + """ + global _on_index_change + _on_index_change = hook + # O(1) lookup table for wikilink resolution: {filename_lower: [{vault, path}, ...]} _file_lookup: Dict[str, List[Dict[str, str]]] = {}