Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update next be a complete string url #4527

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

hamza-56
Copy link
Contributor

@hamza-56 hamza-56 commented Dec 31, 2024

PROD-4266

Update next be a complete string url (like v1) rather than a list in /api/v2/search/all

Comment on lines +128 to +129
if not self.page.has_next():
return None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is has_next calculated here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SearchAfterPagination extends PageNumberPagination from django_elasticsearch_dsl_drf.pagination
PageNumberPagination extends pagination.PageNumberPagination from rest_framework

ref: https://github.com/barseghyanartur/django-elasticsearch-dsl-drf/blob/master/src/django_elasticsearch_dsl_drf/pagination.py

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but that does not answer how it will fit in with SearchAfter pagination where the next is determined from sort values.

Copy link
Contributor Author

@hamza-56 hamza-56 Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def has_next(self):
    return self.number < self.paginator.num_pages

The has_next method checks if there are additional pages available by comparing the current page number (self.number) with the total number of pages (self.paginator.num_pages).

num_pages: Calculates the total number of pages based on the total count of objects (self.count), adjusted for orphans, and divided by per_page. It uses ceil to ensure partial pages are counted as full pages.
count: Determines the total number of objects. If the dataset has a callable count method (e.g., a QuerySet in Django), it uses that for efficiency. Otherwise, it defaults to the length of the object list.

References:

  1. https://github.com/django/django/blob/main/django/core/paginator.py#L205
  2. https://github.com/django/django/blob/main/django/core/paginator.py#L114

The current implementation does not include anything that should break the has_next calculation for search_after pagination in Elasticsearch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants