Skip to content

Added search cutoff ms settings #964

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
May 28, 2024
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
9 changes: 8 additions & 1 deletion .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ update_settings_1: |-
},
'faceting': {
'maxValuesPerFacet': 200
}
},
'searchCutoffMs': 150
})
reset_settings_1: |-
client.index('movies').reset_settings()
Expand Down Expand Up @@ -703,3 +704,9 @@ reset_dictionary_1: |-
client.index('books').reset_dictionary()
create_snapshot_1: |-
client.create_snapshot()
get_search_cutoff_1: |-
client.index('movies').get_search_cutoff_ms()
update_search_cutoff_1: |-
client.index('movies').update_search_cutoff_ms(150)
reset_search_cutoff_1: |-
client.index('movies').reset_search_cutoff_ms()
4 changes: 2 additions & 2 deletions meilisearch/_httprequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def send_request(
http_method: Callable,
path: str,
body: Optional[
Union[Mapping[str, Any], Sequence[Mapping[str, Any]], List[str], str]
Union[Mapping[str, Any], Sequence[Mapping[str, Any]], List[str], str, int]
] = None,
content_type: Optional[str] = None,
) -> Any:
Expand Down Expand Up @@ -90,7 +90,7 @@ def put(
self,
path: str,
body: Optional[
Union[Mapping[str, Any], Sequence[Mapping[str, Any]], List[str], str]
Union[Mapping[str, Any], Sequence[Mapping[str, Any]], List[str], str, int]
] = None,
content_type: Optional[str] = "application/json",
) -> Any:
Expand Down
1 change: 1 addition & 0 deletions meilisearch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Paths:
non_separator_tokens = "non-separator-tokens"
swap = "swap-indexes"
embedders = "embedders"
search_cutoff_ms = "search-cutoff-ms"

def __init__(
self,
Expand Down
60 changes: 60 additions & 0 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,66 @@ def reset_embedders(self) -> TaskInfo:

return TaskInfo(**task)

# SEARCH CUTOFF MS SETTINGS

def get_search_cutoff_ms(self) -> int | None:
"""Get the search cutoff in ms of the index.

Returns
-------
settings:
Integer value of search cutoff in ms of the index.

Raises
------
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
"""
return self.http.get(self.__settings_url_for(self.config.paths.search_cutoff_ms))

def update_search_cutoff_ms(self, body: Union[int, None]) -> TaskInfo:
"""Update the search cutoff in ms of the index.

Parameters
----------
body:
Integer value of the search cutoff time in ms.

Returns
-------
task_info:
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task

Raises
------
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
"""
task = self.http.put(self.__settings_url_for(self.config.paths.search_cutoff_ms), body)

return TaskInfo(**task)

def reset_search_cutoff_ms(self) -> TaskInfo:
"""Reset the search cutoff of the index

Returns
-------
task_info:
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task

Raises
------
MeilisearchApiError
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://www.meilisearch.com/docs/reference/errors/error_codes#meilisearch-errors
"""
task = self.http.delete(
self.__settings_url_for(self.config.paths.search_cutoff_ms),
)

return TaskInfo(**task)

@staticmethod
def _batch(
documents: Sequence[Mapping[str, Any]], batch_size: int
Expand Down
35 changes: 35 additions & 0 deletions tests/settings/test_settings_search_cutoff_meilisearch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
NEW_SEARCH_CUTOFF_MS = 150


def test_get_search_cutoff_ms(empty_index):
"""Tests getting default search cutoff in ms."""
response = empty_index().get_search_cutoff_ms()
assert response is None


def test_update_search_cutoff_ms(empty_index):
"""Tests updating search cutoff in ms."""
index = empty_index()
response = index.update_search_cutoff_ms(NEW_SEARCH_CUTOFF_MS)
update = index.wait_for_task(response.task_uid)
assert update.status == "succeeded"
response = index.get_search_cutoff_ms()
assert NEW_SEARCH_CUTOFF_MS == response


def test_reset_search_cutoff_ms(empty_index):
"""Tests resetting the search cutoff to its default value."""
index = empty_index()
# Update the settings first
response = index.update_search_cutoff_ms(NEW_SEARCH_CUTOFF_MS)
update = index.wait_for_task(response.task_uid)
assert update.status == "succeeded"
# Check the settings have been correctly updated
response = index.get_search_cutoff_ms()
assert NEW_SEARCH_CUTOFF_MS == response
# Check the reset of the settings
response = index.reset_search_cutoff_ms()
update = index.wait_for_task(response.task_uid)
assert update.status == "succeeded"
response = index.get_search_cutoff_ms()
assert response is None