-
Notifications
You must be signed in to change notification settings - Fork 409
Closed
Labels
Description
Bug Report
When we search documents that has children, it searches on the title
field, but only of the descendant document.
The root document does not appear.
Request made:
Request URL: https://docs.numerique.gouv.fr/api/v1.0/documents/[ROOT_ID]/descendants/?page=1&title=de&parent_id=[ROOT_ID]
docs/src/backend/core/api/viewsets.py
Lines 815 to 828 in 67a195f
def descendants(self, request, *args, **kwargs): | |
"""Handle listing descendants of a document""" | |
document = self.get_object() | |
queryset = document.get_descendants().filter(ancestors_deleted_at__isnull=True) | |
queryset = self.filter_queryset(queryset) | |
filterset = DocumentFilter(request.GET, queryset=queryset) | |
if not filterset.is_valid(): | |
raise drf.exceptions.ValidationError(filterset.errors) | |
queryset = filterset.qs | |
return self.get_response_for_queryset(queryset) |
Possible solution
Add root document in the descendants requests ?
def descendants(self, request, *args, **kwargs):
"""Handle listing descendants of a document"""
document = self.get_object()
# Get descendants
- queryset = document.get_descendants().filter(ancestors_deleted_at__isnull=True)
+ descendants_queryset = document.get_descendants().filter(ancestors_deleted_at__isnull=True)
+ # Include the parent document itself in the queryset for search
+ # This allows searching within both the parent and its descendants
+ parent_queryset = self.queryset.filter(pk=document.pk)
+ queryset = descendants_queryset | parent_queryset
+
queryset = self.filter_queryset(queryset)
filterset = DocumentFilter(request.GET, queryset=queryset)
if not filterset.is_valid():
raise drf.exceptions.ValidationError(filterset.errors)
queryset = filterset.qs
return self.get_response_for_queryset(queryset)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done