Skip to content

Add support to the pagination setting customization #504

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

Merged
merged 1 commit into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions meilisearch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Paths():
sortable_attributes = 'sortable-attributes'
typo_tolerance = 'typo-tolerance'
dumps = 'dumps'
pagination = 'pagination'

def __init__(
self,
Expand Down
57 changes: 57 additions & 0 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,63 @@ def reset_typo_tolerance(self) -> Dict[str, Any]:
self.__settings_url_for(self.config.paths.typo_tolerance),
)

def get_pagination_settings(self) -> Dict[str, Any]:
"""Get pagination settngs of the index.

Returns
-------
settings: dict
Dictionary containing the pagination settings of the index.

Raises
------
MeiliSearchApiError
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
"""
return self.http.get(self.__settings_url_for(self.config.paths.pagination))

def update_pagination_settings(self, body: Dict[str, Any]) -> Dict[str, Any]:
"""Update the pagination settings of the index.

Parameters
----------
body: dict
Dictionary containing the pagination settings.
https://docs.meilisearch.com/reference/api/pagination.html#update-pagination-settings

Returns
-------
task:
Dictionary containing a task to track the informations about the progress of an asynchronous process.
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task

Raises
------
MeiliSearchApiError
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
"""
return self.http.patch(
path=self.__settings_url_for(self.config.paths.pagination),
body=body
)


def reset_pagination_settings(self) -> Dict[str, Any]:
"""Reset pagination settings of the index to default values.

Returns
-------
task:
Dictionary containing a task to track the informations about the progress of an asynchronous process.
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task

Raises
------
MeiliSearchApiError
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
"""
return self.http.delete(self.__settings_url_for(self.config.paths.pagination))

@staticmethod
def _batch(
documents: List[Dict[str, Any]], batch_size: int
Expand Down
31 changes: 31 additions & 0 deletions tests/settings/test_settings_pagination.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
DEFAULT_MAX_TOTAL_HITS = 1000
NEW_MAX_TOTAL_HITS = {'maxTotalHits': 2222}


def test_get_pagination_settings(empty_index):
response = empty_index().get_pagination_settings()

assert isinstance(response, dict)
assert { 'maxTotalHits': DEFAULT_MAX_TOTAL_HITS } == response


def test_update_pagination_settings(empty_index):
index = empty_index()
response = index.update_pagination_settings(NEW_MAX_TOTAL_HITS)
assert isinstance(response, dict)
assert 'taskUid' in response

index.wait_for_task(response['taskUid'])
response = index.get_pagination_settings()
assert isinstance(response, dict)
assert NEW_MAX_TOTAL_HITS == response


def test_delete_pagination_settings(empty_index):
index = empty_index()
response = index.reset_pagination_settings()

index.wait_for_task(response['taskUid'])
response = index.get_pagination_settings()
assert isinstance(response, dict)
assert { 'maxTotalHits': DEFAULT_MAX_TOTAL_HITS } == response