Skip to content

Commit 37ec63e

Browse files
bors[bot]Volodymyr Yevtushenko
and
Volodymyr Yevtushenko
authored
Merge #506
506: Add faceting settings customization r=alallema a=voloyev # Pull Request ## What does this PR do? Fixes #496 ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue? - [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: Volodymyr Yevtushenko <[email protected]>
2 parents 5ad732f + 10be1e0 commit 37ec63e

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

meilisearch/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Paths():
2828
typo_tolerance = 'typo-tolerance'
2929
dumps = 'dumps'
3030
pagination = 'pagination'
31+
faceting = 'faceting'
3132

3233
def __init__(
3334
self,

meilisearch/index.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,65 @@ def reset_pagination_settings(self) -> Dict[str, Any]:
12881288
"""
12891289
return self.http.delete(self.__settings_url_for(self.config.paths.pagination))
12901290

1291+
def get_faceting_settings(self) -> Dict[str, Any]:
1292+
"""Get the faceting settings of an index.
1293+
1294+
Returns
1295+
-------
1296+
settings: dict
1297+
Dictionary containing the faceting settings of the index.
1298+
1299+
Raises
1300+
------
1301+
MeiliSearchApiError
1302+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
1303+
"""
1304+
1305+
return self.http.get(self.__settings_url_for(self.config.paths.faceting))
1306+
1307+
def update_faceting_settings(self, body: Dict[str, Any]) -> Dict[str, Any]:
1308+
"""Update the faceting settings of the index.
1309+
1310+
Parameters
1311+
----------
1312+
body: dict
1313+
Dictionary containing the faceting settings.
1314+
https://docs.meilisearch.com/reference/api/faceting.html#update-faceting-settings
1315+
1316+
Returns
1317+
-------
1318+
task:
1319+
Dictionary containing a task to track the informations about the progress of an asynchronous process.
1320+
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task
1321+
1322+
Raises
1323+
------
1324+
MeiliSearchApiError
1325+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
1326+
"""
1327+
return self.http.patch(
1328+
path=self.__settings_url_for(self.config.paths.faceting),
1329+
body=body
1330+
)
1331+
1332+
1333+
def reset_faceting_settings(self) -> Dict[str, Any]:
1334+
"""Reset faceting settings of the index to default values.
1335+
1336+
Returns
1337+
-------
1338+
task:
1339+
Dictionary containing a task to track the informations about the progress of an asynchronous process.
1340+
https://docs.meilisearch.com/reference/api/tasks.html#get-one-task
1341+
1342+
Raises
1343+
------
1344+
MeiliSearchApiError
1345+
An error containing details about why Meilisearch can't process your request. Meilisearch error codes are described here: https://docs.meilisearch.com/errors/#meilisearch-errors
1346+
"""
1347+
return self.http.delete(self.__settings_url_for(self.config.paths.faceting))
1348+
1349+
12911350
@staticmethod
12921351
def _batch(
12931352
documents: List[Dict[str, Any]], batch_size: int
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
DEFAULT_MAX_VALUE_PER_FACET = 100
2+
NEW_MAX_VALUE_PER_FACET = {'maxValuesPerFacet': 200 }
3+
4+
5+
def test_get_faceting_settings(empty_index):
6+
response = empty_index().get_faceting_settings()
7+
8+
assert isinstance(response, dict)
9+
assert { 'maxValuesPerFacet': DEFAULT_MAX_VALUE_PER_FACET } == response
10+
11+
12+
def test_update_faceting_settings(empty_index):
13+
index = empty_index()
14+
response = index.update_faceting_settings(NEW_MAX_VALUE_PER_FACET)
15+
assert isinstance(response, dict)
16+
assert 'taskUid' in response
17+
18+
index.wait_for_task(response['taskUid'])
19+
response = index.get_faceting_settings()
20+
assert isinstance(response, dict)
21+
assert NEW_MAX_VALUE_PER_FACET == response
22+
23+
24+
def test_delete_faceting_settings(empty_index):
25+
index = empty_index()
26+
response = index.reset_faceting_settings()
27+
28+
index.wait_for_task(response['taskUid'])
29+
response = index.get_faceting_settings()
30+
assert isinstance(response, dict)
31+
assert { 'maxValuesPerFacet': DEFAULT_MAX_VALUE_PER_FACET } == response

0 commit comments

Comments
 (0)