Skip to content

Commit

Permalink
Merge #964
Browse files Browse the repository at this point in the history
964: Added search cutoff ms settings r=sanders41 a=the-sinner

# Pull Request

## Related issue
Fixes #959 

## What does this PR do?
- adds the search cutoff ms settings

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [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: Shalabh Agarwal <shalabhagarwal1024@gmail.com>
  • Loading branch information
meili-bors[bot] and the-sinner authored May 28, 2024
2 parents 75860f8 + 40f92f9 commit da08f26
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 3 deletions.
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

0 comments on commit da08f26

Please sign in to comment.