Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support localized-attributes settings #1060

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ellnix
Copy link
Contributor

@ellnix ellnix commented Jan 15, 2025

Pull Request

Related issue

Fixes #1011

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Not very experienced with python, let me know if I should have created a model for the localized attributes, similar to embedders or proximity precision.

Regarding #1011, I don't think anything needs to change in the search parameters, since those seem to be dynamic anyway.

@curquiza curquiza added the enhancement New feature or request label Jan 15, 2025
@curquiza curquiza requested a review from sanders41 January 15, 2025 13:40
@@ -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]:
Copy link
Collaborator

@sanders41 sanders41 Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very experienced with python, let me know if I should have created a model for the localized attributes, similar to embedders or proximity precision.

Let's do that, it will make it easier to work with. So you will have:

class LocalizedAttributes(CamelBase):
    ...
Suggested change
def get_localized_attributes(self) -> Union[List[Dict[str, List[str]]], None]:
def get_localized_attributes(self) -> Union[List[LocalizedAttributes], None]:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for the feedback, it's very detailed!

So by your suggestion the LocalizedAttributes class should encapsulate the list, which limits me to having a class with just one field for attributes.

Should I also make another class for each entry in the list?

I'm trying to find out if this should be similar to Rust structs, where you make struct after struct until you have the entire structure represented in code (sorry if you do not use rust, I suppose structs in C aren't too different in this respect)

P. S.: will fix this very soon

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent question! You are correct this should have been a list. I updated my suggestion for this.

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))
Copy link
Collaborator

@sanders41 sanders41 Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return self.http.get(self.__settings_url_for(self.config.paths.localized_attributes))
attributes = self.http.get(self.__settings_url_for(self.config.paths.localized_attributes))
return [LocalizedAttributes(**attribute) for attribute in attributes]

Comment on lines +2062 to +2064
def update_localized_attributes(
self, body: Union[List[Dict[str, List[str]]], None]
) -> TaskInfo:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have tried to move to Mapping for these to give more flexablitiy.

Suggested change
def update_localized_attributes(
self, body: Union[List[Dict[str, List[str]]], None]
) -> TaskInfo:
def update_localized_attributes(
self, body: Union[List[Mapping[str, List[str]]], None]
) -> TaskInfo:

@@ -0,0 +1,35 @@
NEW_LOCALIZED_ATTRIBUTES = [{"attributePatterns": ["title"], "locales": ["eng"]}]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to use the new class.

update = index.wait_for_task(response.task_uid)
assert update.status == "succeeded"
response = index.get_localized_attributes()
assert NEW_LOCALIZED_ATTRIBUTES == response
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this may fail after updating to a class, if it does changing to assert [x.model_dump for x in NEW_LOCALIZED_ATTRIBUTES] == [x.model_dump() for x in response] should fix it.

assert update.status == "succeeded"
# Check the settings have been correctly updated
response = index.get_localized_attributes()
assert NEW_LOCALIZED_ATTRIBUTES == response
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previous, this may fail with class and the same fix should work if so.

@sanders41
Copy link
Collaborator

Regarding #1011, I don't think anything needs to change in the search parameters, since those seem to be dynamic anyway.

You are correct here, it will work as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v1.10.0] Language settings & search parameter
3 participants