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:
|
2026-07-23 23:00:08 +02:00
|
|
|
"""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":
|
2026-07-23 23:00:08 +02:00
|
|
|
from app.search.meili import MeiliSearchBackend
|
|
|
|
|
|
|
|
|
|
_backend = MeiliSearchBackend()
|
|
|
|
|
else:
|
|
|
|
|
_backend = PgSearchBackend()
|
2026-07-17 23:20:34 +02:00
|
|
|
return _backend
|