Skip to content

Commit fa0a8ef

Browse files
committed
Added search cutoff ms settings
1 parent 75860f8 commit fa0a8ef

File tree

5 files changed

+106
-3
lines changed

5 files changed

+106
-3
lines changed

.code-samples.meilisearch.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ update_settings_1: |-
139139
},
140140
'faceting': {
141141
'maxValuesPerFacet': 200
142-
}
142+
},
143+
'searchCutoffMs': 150
143144
})
144145
reset_settings_1: |-
145146
client.index('movies').reset_settings()
@@ -703,3 +704,9 @@ reset_dictionary_1: |-
703704
client.index('books').reset_dictionary()
704705
create_snapshot_1: |-
705706
client.create_snapshot()
707+
get_search_cutoff_1: |-
708+
client.index('movies').get_search_cutoff_ms()
709+
update_search_cutoff_1: |-
710+
client.index('movies').update_search_cutoff_ms(150)
711+
reset_search_cutoff_1: |-
712+
client.index('movies').reset_search_cutoff_ms()

meilisearch/_httprequests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def send_request(
2828
http_method: Callable,
2929
path: str,
3030
body: Optional[
31-
Union[Mapping[str, Any], Sequence[Mapping[str, Any]], List[str], str]
31+
Union[Mapping[str, Any], Sequence[Mapping[str, Any]], List[str], str, int]
3232
] = None,
3333
content_type: Optional[str] = None,
3434
) -> Any:
@@ -90,7 +90,7 @@ def put(
9090
self,
9191
path: str,
9292
body: Optional[
93-
Union[Mapping[str, Any], Sequence[Mapping[str, Any]], List[str], str]
93+
Union[Mapping[str, Any], Sequence[Mapping[str, Any]], List[str], str, int]
9494
] = None,
9595
content_type: Optional[str] = "application/json",
9696
) -> Any:

meilisearch/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Paths:
3939
non_separator_tokens = "non-separator-tokens"
4040
swap = "swap-indexes"
4141
embedders = "embedders"
42+
search_cutoff_ms = "search-cutoff-ms"
4243

4344
def __init__(
4445
self,

meilisearch/index.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,66 @@ def reset_embedders(self) -> TaskInfo:
18561856
)
18571857

18581858
return TaskInfo(**task)
1859+
1860+
# SEARCH CUTOFF MS SETTINGS
1861+
1862+
def get_search_cutoff_ms(self) -> int | None:
1863+
"""Get the search cutoff in ms of the index.
1864+
1865+
Returns
1866+
-------
1867+
settings:
1868+
Integer value of search cutoff in ms of the index.
1869+
1870+
Raises
1871+
------
1872+
MeilisearchApiError
1873+
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
1874+
"""
1875+
return self.http.get(self.__settings_url_for(self.config.paths.search_cutoff_ms))
1876+
1877+
def update_search_cutoff_ms(self, body: Union[int, None]) -> TaskInfo:
1878+
"""Update the search cutoff in ms of the index.
1879+
1880+
Parameters
1881+
----------
1882+
body:
1883+
Integer value of the search cutoff time in ms.
1884+
1885+
Returns
1886+
-------
1887+
task_info:
1888+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
1889+
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
1890+
1891+
Raises
1892+
------
1893+
MeilisearchApiError
1894+
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
1895+
"""
1896+
task = self.http.put(self.__settings_url_for(self.config.paths.search_cutoff_ms), body)
1897+
1898+
return TaskInfo(**task)
1899+
1900+
def reset_search_cutoff_ms(self) -> TaskInfo:
1901+
"""Reset the search cutoff of the index
1902+
1903+
Returns
1904+
-------
1905+
task_info:
1906+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
1907+
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
1908+
1909+
Raises
1910+
------
1911+
MeilisearchApiError
1912+
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
1913+
"""
1914+
task = self.http.delete(
1915+
self.__settings_url_for(self.config.paths.search_cutoff_ms),
1916+
)
1917+
1918+
return TaskInfo(**task)
18591919

18601920
@staticmethod
18611921
def _batch(
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
NEW_SEARCH_CUTOFF_MS = 150
2+
3+
4+
def test_get_search_cutoff_ms(empty_index):
5+
"""Tests getting default search cutoff in ms."""
6+
response = empty_index().get_search_cutoff_ms()
7+
assert response is None
8+
9+
10+
def test_update_search_cutoff_ms(empty_index):
11+
"""Tests updating search cutoff in ms."""
12+
index = empty_index()
13+
response = index.update_search_cutoff_ms(NEW_SEARCH_CUTOFF_MS)
14+
update = index.wait_for_task(response.task_uid)
15+
assert update.status == "succeeded"
16+
response = index.get_search_cutoff_ms()
17+
assert NEW_SEARCH_CUTOFF_MS == response
18+
19+
20+
def test_reset_search_cutoff_ms(empty_index):
21+
"""Tests resetting the search cutoff to its default value."""
22+
index = empty_index()
23+
# Update the settings first
24+
response = index.update_search_cutoff_ms(NEW_SEARCH_CUTOFF_MS)
25+
update = index.wait_for_task(response.task_uid)
26+
assert update.status == "succeeded"
27+
# Check the settings have been correctly updated
28+
response = index.get_search_cutoff_ms()
29+
assert NEW_SEARCH_CUTOFF_MS == response
30+
# Check the reset of the settings
31+
response = index.reset_search_cutoff_ms()
32+
update = index.wait_for_task(response.task_uid)
33+
assert update.status == "succeeded"
34+
response = index.get_search_cutoff_ms()
35+
assert response is None

0 commit comments

Comments
 (0)