(backend) handle indexer crash

I fall back on title_search when the indexer is not
configured, but I did not handle indexer crashs.
I am adding the try except to handle indexer crashes.

Signed-off-by: charles <[email protected]>
This commit is contained in:
charles
2026-02-16 16:43:15 +01:00
parent 32ee62deae
commit f7a90d10b6
+12 -4
View File
@@ -1183,11 +1183,19 @@ class DocumentViewSet(
params.is_valid(raise_exception=True)
indexer = get_document_indexer()
if indexer:
if indexer is None:
# fallback on title search if the indexer is not configured
return self._title_search(request, params.validated_data, *args, **kwargs)
try:
return self._search_with_indexer(indexer, request, params=params)
except requests.exceptions.RequestException as e:
logger.error("Error while searching documents with indexer: %s", e)
# fallback on title search if the indexer is not reached
return self._title_search(
request, params.validated_data, *args, **kwargs
)
# The indexer is not configured, we fallback on title search
return self.title_search(request, params.validated_data, *args, **kwargs)
@staticmethod
def _search_with_indexer(indexer, request, params):
@@ -1216,7 +1224,7 @@ class DocumentViewSet(
}
)
def title_search(self, request, validated_data, *args, **kwargs):
def _title_search(self, request, validated_data, *args, **kwargs):
"""
Fallback search method when no indexer is configured.
Only searches in the title field of documents.