Skip to content

Commit

Permalink
fix: sorting order issue in search/all endpoint with search_after
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Jan 10, 2025
1 parent b25b16e commit e9ba49a
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions course_discovery/apps/edx_elasticsearch_dsl_extensions/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,11 @@ def get_next_link(self):
return replace_query_param(url, self.search_after_param, json.dumps(last_item_sort))

def _get_last_item_sort(self):
last_item = self.page.object_list[-1] if self.page.object_list else None
return list(last_item.meta.sort) if last_item else None

def get_paginated_response(self, data):
"""
Get paginated response, including search_after value for the next page.
"""
response = super().get_paginated_response(data)
view = self.request.parser_context.get("view")
last_item = getattr(view, "last_item", None)
search_after = last_item.meta.sort.copy() if last_item else None
next_link = response.data.pop("next", None)
response.data["next"] = search_after if next_link else None
return response
last_item = last_item.meta.sort.copy() if last_item else None
setattr(view, "last_item", None) # clearing the last_item attribute to prevent it from being used in the next request
return last_item


class BaseElasticsearchDocumentViewSet(mixins.DetailMixin, mixins.FacetMixin, DocumentViewSet):
Expand Down

0 comments on commit e9ba49a

Please sign in to comment.