Skip to content

Commit 3150bf8

Browse files
authored
Search: reduce page size in search API pagination (#12549)
50 results is a lot, user probably don't even read past the first 10 results. Returning lots of results means: - More work for ES - More data to transfer. Each result has sub-results (blocks), which also return the source text together with the highlighted portion. - More time to render the results in the UI. The search addon could possibly fetch less results (15? 20?). But just making this a change for all API calls for now (maybe we can be even made this 25). Some silly testing showed improvements of ~10-50ms
1 parent c2d9491 commit 3150bf8

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

readthedocs/search/api/pagination.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def previous_page_number(self):
3535
class SearchPagination(PageNumberPagination):
3636
"""Paginator for the results of PageSearch."""
3737

38-
page_size = 50
38+
page_size = 15
3939
page_size_query_param = "page_size"
40-
max_page_size = 100
40+
max_page_size = 30
4141

4242
def _get_page_number(self, number):
4343
try:

readthedocs/search/tests/test_api.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ def test_doc_search_pagination(self, api_client, project):
183183
assert resp.data["count"] == 61
184184
# Check there are next url
185185
assert resp.data["next"] is not None
186-
# There should be only 50 data as the pagination is 50 by default
187-
assert len(resp.data["results"]) == 50
186+
# Pagination default page size is 15
187+
assert len(resp.data["results"]) == 15
188188

189189
# Check for page 2
190190
search_params["page"] = 2
@@ -193,10 +193,22 @@ def test_doc_search_pagination(self, api_client, project):
193193

194194
# Check the count is 61 (1 existing and 60 new created)
195195
assert resp.data["count"] == 61
196-
# We don't have more results after this page
196+
# We istill have more results.
197+
assert resp.data["next"] is not None
198+
# Pagination default page size is 15
199+
assert len(resp.data["results"]) == 15
200+
201+
# Check for last page
202+
search_params["page"] = 5
203+
resp = self.get_search(api_client, search_params)
204+
assert resp.status_code == 200
205+
206+
# Check the count is 61 (1 existing and 60 new created)
207+
assert resp.data["count"] == 61
208+
# No more results after this
197209
assert resp.data["next"] is None
198-
# There should be only the 11 left
199-
assert len(resp.data["results"]) == 11
210+
# We have only 1 result in the last page
211+
assert len(resp.data["results"]) == 1
200212

201213
# Add `page_size` parameter and check the data is paginated accordingly
202214
search_params["page_size"] = 5

0 commit comments

Comments
 (0)