Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -732,3 +732,13 @@ reset_proximity_precision_settings_1: |-
client.index('books').reset_proximity_precision()
search_parameter_reference_ranking_score_threshold_1: |-
client.index('INDEX_NAME').search('badman', { 'rankingScoreThreshold': 0.2 })
search_parameter_reference_locales_1: |-
client.index('INDEX_NAME').search('進撃の巨人', { 'locales': ['jpn'] })
get_localized_attribute_settings_1: |-
client.index('INDEX_NAME').get_localized_attributes()
update_localized_attribute_settings_1: |-
client.index('INDEX_NAME').update_localized_attributes([
{'attribute_patterns': ['*_ja'], 'locales': ['jpn']}
])
reset_localized_attribute_settings_1: |-
client.index('INDEX_NAME').reset_localized_attributes()
1 change: 1 addition & 0 deletions meilisearch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Paths:
embedders = "embedders"
search_cutoff_ms = "search-cutoff-ms"
proximity_precision = "proximity-precision"
localized_attributes = "localized-attributes"

def __init__(
self,
Expand Down
62 changes: 62 additions & 0 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,68 @@ def reset_proximity_precision(self) -> TaskInfo:

return TaskInfo(**task)

# LOCALIZED ATTRIBUTES SETTINGS

def get_localized_attributes(self) -> Union[List[Dict[str, List[str]]], None]:
"""Get the proximity_precision of the index.

Returns
-------
settings:
localized_attributes 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.localized_attributes))

def update_localized_attributes(
self, body: Union[List[Dict[str, List[str]]], None]
) -> TaskInfo:
"""Update the localized_attributes of the index.

Parameters
----------
body:
localized_attributes

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.localized_attributes), body)

return TaskInfo(**task)

def reset_localized_attributes(self) -> TaskInfo:
"""Reset the localized_attributes 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.localized_attributes),
)

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_localized_attributes_meilisearch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
NEW_LOCALIZED_ATTRIBUTES = [{"attributePatterns": ["title"], "locales": ["eng"]}]


def test_get_localized_attributes(empty_index):
"""Tests getting default localized_attributes."""
response = empty_index().get_localized_attributes()
assert response is None


def test_update_localized_attributes(empty_index):
"""Tests updating proximity precision."""
index = empty_index()
response = index.update_localized_attributes(NEW_LOCALIZED_ATTRIBUTES)
update = index.wait_for_task(response.task_uid)
assert update.status == "succeeded"
response = index.get_localized_attributes()
assert NEW_LOCALIZED_ATTRIBUTES == response


def test_reset_localized_attributes(empty_index):
"""Tests resetting the proximity precision to its default value."""
index = empty_index()
# Update the settings first
response = index.update_localized_attributes(NEW_LOCALIZED_ATTRIBUTES)
update = index.wait_for_task(response.task_uid)
assert update.status == "succeeded"
# Check the settings have been correctly updated
response = index.get_localized_attributes()
assert NEW_LOCALIZED_ATTRIBUTES == response
# Check the reset of the settings
response = index.reset_localized_attributes()
update = index.wait_for_task(response.task_uid)
assert update.status == "succeeded"
response = index.get_localized_attributes()
assert response is None
Loading