Skip to content

Commit 18760bc

Browse files
committed
Add methods for Facet Search settings requests
1 parent 4635314 commit 18760bc

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

.code-samples.meilisearch.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,12 @@ update_pagination_settings_1: |-
634634
client.index('books').update_pagination_settings({'maxTotalHits': 100})
635635
reset_pagination_settings_1: |-
636636
client.index('books').reset_pagination_settings()
637+
get_facet_search_settings_1: |-
638+
client.index('books').get_facet_search_settings()
639+
update_facet_search_settings_1: |-
640+
client.index('books').update_facet_search_settings(False)
641+
reset_facet_search_settings_1: |-
642+
client.index('books').reset_facet_search_settings()
637643
get_faceting_settings_1: |-
638644
client.index('books').get_faceting_settings()
639645
update_faceting_settings_1: |-

meilisearch/index.py

+51-1
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,57 @@ def reset_pagination_settings(self) -> TaskInfo:
16281628

16291629
return TaskInfo(**task)
16301630

1631+
def get_facet_search_settings(self) -> bool:
1632+
"""Get the facet search settings of an index.
1633+
1634+
Returns
1635+
-------
1636+
bool:
1637+
True if facet search is enabled, False if disabled.
1638+
Raises
1639+
------
1640+
MeilisearchApiError
1641+
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
1642+
"""
1643+
1644+
return self.http.get(self.__settings_url_for(self.config.paths.facet_search))
1645+
1646+
def update_facet_search_settings(self, body: Union[bool, None]) -> TaskInfo:
1647+
"""Update the facet search settings of the index.
1648+
1649+
Parameters
1650+
----------
1651+
body: bool
1652+
True to enable facet search, False to disable it.
1653+
1654+
Returns
1655+
-------
1656+
task_info:
1657+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
1658+
https://www.meilisearch.com/docs/reference/api/tasks#get-one-task
1659+
1660+
Raises
1661+
------
1662+
MeilisearchApiError
1663+
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
1664+
"""
1665+
task = self.http.put(self.__settings_url_for(self.config.paths.facet_search), body=body)
1666+
1667+
return TaskInfo(**task)
1668+
1669+
def reset_facet_search_settings(self) -> TaskInfo:
1670+
"""Reset facet search settings of the index to default values.
1671+
1672+
Returns
1673+
-------
1674+
task_info:
1675+
TaskInfo instance containing information about a task to track the progress of an asynchronous process.
1676+
https://www.meilisearch.com/docs/reference/api/tasks
1677+
"""
1678+
task = self.http.delete(self.__settings_url_for(self.config.paths.facet_search))
1679+
1680+
return TaskInfo(**task)
1681+
16311682
def get_faceting_settings(self) -> Faceting:
16321683
"""Get the faceting settings of an index.
16331684
@@ -1641,7 +1692,6 @@ def get_faceting_settings(self) -> Faceting:
16411692
MeilisearchApiError
16421693
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
16431694
"""
1644-
16451695
faceting = self.http.get(self.__settings_url_for(self.config.paths.faceting))
16461696

16471697
return Faceting(**faceting)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
DEFAULT_FACET_SEARCH_SETTINGS_STATUS = True
2+
ENABLED_FACET_SEARCH_SETTINGS_STATUS = True
3+
DISABLED_FACET_SEARCH_SETTINGS_STATUS = False
4+
5+
6+
def test_get_facet_search_settings(empty_index):
7+
response = empty_index().get_facet_search_settings()
8+
9+
assert DEFAULT_FACET_SEARCH_SETTINGS_STATUS == response
10+
11+
12+
def test_update_facet_search_settings(empty_index):
13+
index = empty_index()
14+
15+
response = index.update_facet_search_settings(DISABLED_FACET_SEARCH_SETTINGS_STATUS)
16+
index.wait_for_task(response.task_uid)
17+
response = index.get_facet_search_settings()
18+
assert DISABLED_FACET_SEARCH_SETTINGS_STATUS == response
19+
20+
response = index.update_facet_search_settings(ENABLED_FACET_SEARCH_SETTINGS_STATUS)
21+
index.wait_for_task(response.task_uid)
22+
response = index.get_facet_search_settings()
23+
assert ENABLED_FACET_SEARCH_SETTINGS_STATUS == response
24+
25+
26+
def test_reset_facet_search_settings(empty_index):
27+
index = empty_index()
28+
29+
response = index.update_facet_search_settings(DISABLED_FACET_SEARCH_SETTINGS_STATUS)
30+
index.wait_for_task(response.task_uid)
31+
response = index.get_facet_search_settings()
32+
assert DISABLED_FACET_SEARCH_SETTINGS_STATUS == response
33+
assert DEFAULT_FACET_SEARCH_SETTINGS_STATUS != response
34+
35+
response = index.reset_facet_search_settings()
36+
index.wait_for_task(response.task_uid)
37+
response = index.get_facet_search_settings()
38+
assert DEFAULT_FACET_SEARCH_SETTINGS_STATUS == response

0 commit comments

Comments
 (0)