Skip to content

Commit ec56487

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

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
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/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
@@ -1881,3 +1881,63 @@ def _build_url(
18811881
if primary_key is None and csv_delimiter is None:
18821882
return f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}"
18831883
return f"{self.config.paths.index}/{self.uid}/{self.config.paths.document}?{parse.urlencode(parameters)}"
1884+
1885+
# SEARCH CUTOFF MS SETTINGS
1886+
1887+
def get_search_cutoff_ms(self) -> int | None:
1888+
"""Get the search cutoff in ms of the index.
1889+
1890+
Returns
1891+
-------
1892+
search_cutoffms:
1893+
Integer value of search cutoff in ms of the index.
1894+
1895+
Raises
1896+
------
1897+
MeilisearchApiError
1898+
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
1899+
"""
1900+
return self.http.get(self.__settings_url_for(self.config.paths.search_cutoff_ms))
1901+
1902+
def update_search_cutoff_ms(self, body: Union[int, None]) -> TaskInfo:
1903+
"""Update the search cutoff in ms of the index.
1904+
1905+
Parameters
1906+
----------
1907+
body:
1908+
List of the new dictionary entries.
1909+
1910+
Returns
1911+
-------
1912+
task_info:
1913+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
1914+
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
1915+
1916+
Raises
1917+
------
1918+
MeilisearchApiError
1919+
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
1920+
"""
1921+
task = self.http.put(self.__settings_url_for(self.config.paths.search_cutoff_ms), body)
1922+
1923+
return TaskInfo(**task)
1924+
1925+
def reset_search_cutoff_ms(self) -> TaskInfo:
1926+
"""Reset the search cutoff of the index
1927+
1928+
Returns
1929+
-------
1930+
task_info:
1931+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
1932+
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
1933+
1934+
Raises
1935+
------
1936+
MeilisearchApiError
1937+
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
1938+
"""
1939+
task = self.http.delete(
1940+
self.__settings_url_for(self.config.paths.search_cutoff_ms),
1941+
)
1942+
1943+
return TaskInfo(**task)
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 == 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 == None

0 commit comments

Comments
 (0)