Skip to content

Commit 5ad732f

Browse files
bors[bot]Volodymyr Yevtushenko
and
Volodymyr Yevtushenko
authored
Merge #504
504: Add support to the pagination setting customization r=alallema a=voloyev # Pull Request ## What does this PR do? Fixes #495 ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Volodymyr Yevtushenko <[email protected]>
2 parents e57285f + 80d3a1f commit 5ad732f

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

meilisearch/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Paths():
2727
sortable_attributes = 'sortable-attributes'
2828
typo_tolerance = 'typo-tolerance'
2929
dumps = 'dumps'
30+
pagination = 'pagination'
3031

3132
def __init__(
3233
self,

meilisearch/index.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,63 @@ def reset_typo_tolerance(self) -> Dict[str, Any]:
12311231
self.__settings_url_for(self.config.paths.typo_tolerance),
12321232
)
12331233

1234+
def get_pagination_settings(self) -> Dict[str, Any]:
1235+
"""Get pagination settngs of the index.
1236+
1237+
Returns
1238+
-------
1239+
settings: dict
1240+
Dictionary containing the pagination settings of the index.
1241+
1242+
Raises
1243+
------
1244+
MeiliSearchApiError
1245+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
1246+
"""
1247+
return self.http.get(self.__settings_url_for(self.config.paths.pagination))
1248+
1249+
def update_pagination_settings(self, body: Dict[str, Any]) -> Dict[str, Any]:
1250+
"""Update the pagination settings of the index.
1251+
1252+
Parameters
1253+
----------
1254+
body: dict
1255+
Dictionary containing the pagination settings.
1256+
https://docs.meilisearch.com/reference/api/pagination.html#update-pagination-settings
1257+
1258+
Returns
1259+
-------
1260+
task:
1261+
Dictionary containing a task to track the informations about the progress of an asynchronous process.
1262+
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task
1263+
1264+
Raises
1265+
------
1266+
MeiliSearchApiError
1267+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
1268+
"""
1269+
return self.http.patch(
1270+
path=self.__settings_url_for(self.config.paths.pagination),
1271+
body=body
1272+
)
1273+
1274+
1275+
def reset_pagination_settings(self) -> Dict[str, Any]:
1276+
"""Reset pagination settings of the index to default values.
1277+
1278+
Returns
1279+
-------
1280+
task:
1281+
Dictionary containing a task to track the informations about the progress of an asynchronous process.
1282+
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task
1283+
1284+
Raises
1285+
------
1286+
MeiliSearchApiError
1287+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
1288+
"""
1289+
return self.http.delete(self.__settings_url_for(self.config.paths.pagination))
1290+
12341291
@staticmethod
12351292
def _batch(
12361293
documents: List[Dict[str, Any]], batch_size: int
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
DEFAULT_MAX_TOTAL_HITS = 1000
2+
NEW_MAX_TOTAL_HITS = {'maxTotalHits': 2222}
3+
4+
5+
def test_get_pagination_settings(empty_index):
6+
response = empty_index().get_pagination_settings()
7+
8+
assert isinstance(response, dict)
9+
assert { 'maxTotalHits': DEFAULT_MAX_TOTAL_HITS } == response
10+
11+
12+
def test_update_pagination_settings(empty_index):
13+
index = empty_index()
14+
response = index.update_pagination_settings(NEW_MAX_TOTAL_HITS)
15+
assert isinstance(response, dict)
16+
assert 'taskUid' in response
17+
18+
index.wait_for_task(response['taskUid'])
19+
response = index.get_pagination_settings()
20+
assert isinstance(response, dict)
21+
assert NEW_MAX_TOTAL_HITS == response
22+
23+
24+
def test_delete_pagination_settings(empty_index):
25+
index = empty_index()
26+
response = index.reset_pagination_settings()
27+
28+
index.wait_for_task(response['taskUid'])
29+
response = index.get_pagination_settings()
30+
assert isinstance(response, dict)
31+
assert { 'maxTotalHits': DEFAULT_MAX_TOTAL_HITS } == response

0 commit comments

Comments
 (0)