♻️(backend) rename DocumentViewset::_title_search in _search_title

We rename the private method _title_search in _search_title in the
DocumentViewset for having the search methods prefixed with _search
This commit is contained in:
Manuel Raynaud
2026-05-27 17:41:38 +02:00
parent e85e7d6c65
commit b77f7ab6f4
3 changed files with 38 additions and 30 deletions
+12 -6
View File
@@ -1434,21 +1434,27 @@ class DocumentViewSet(
params.is_valid(raise_exception=True)
search_type = self._get_search_type()
if search_type == SearchType.TITLE:
return self._title_search(request, params.validated_data, *args, **kwargs)
return self._search_using_database(
request, params.validated_data, *args, **kwargs
)
indexer = get_document_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)
return self._search_using_database(
request, params.validated_data, *args, **kwargs
)
try:
return self._search_with_indexer(
return self._search_using_indexer(
indexer, request, params=params, search_type=search_type
)
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)
return self._search_using_database(
request, params.validated_data, *args, **kwargs
)
def _get_search_type(self) -> SearchType:
"""
@@ -1464,7 +1470,7 @@ class DocumentViewSet(
return SearchType.TITLE
@staticmethod
def _search_with_indexer(indexer, request, params, search_type):
def _search_using_indexer(indexer, request, params, search_type):
"""
Returns a list of documents matching the query (q) according to the configured indexer.
"""
@@ -1491,7 +1497,7 @@ class DocumentViewSet(
}
)
def _title_search(self, request, validated_data, *args, **kwargs):
def _search_using_database(self, request, validated_data, *args, **kwargs):
"""
Fallback search method when no indexer is configured.
Only searches in the title field of documents.