Files
webmail-client/backend/app/search/factory.py
T

24 lines
715 B
Python
Raw Normal View History

2026-07-17 23:20:34 +02:00
"""Select the active SearchBackend from config (SPEC §8.1, env SEARCH_BACKEND)."""
from __future__ import annotations
from app.config import get_settings
from app.search.base import SearchBackend
from app.search.pg import PgSearchBackend
_backend: SearchBackend | None = None
def get_search_backend() -> SearchBackend:
"""Return the process-wide SearchBackend (``pg`` or ``meili`` per SEARCH_BACKEND)."""
2026-07-17 23:20:34 +02:00
global _backend
if _backend is None:
which = get_settings().search_backend
if which == "meili":
from app.search.meili import MeiliSearchBackend
_backend = MeiliSearchBackend()
else:
_backend = PgSearchBackend()
2026-07-17 23:20:34 +02:00
return _backend