diff --git a/src/backend/core/api/viewsets.py b/src/backend/core/api/viewsets.py index ec40e4ed..8f38bde8 100644 --- a/src/backend/core/api/viewsets.py +++ b/src/backend/core/api/viewsets.py @@ -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.