Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
44 changes: 22 additions & 22 deletions meilisearch_python_sdk/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3593,7 +3593,7 @@ async def reset_synonyms(self) -> TaskInfo:

return TaskInfo(**response.json())

async def get_filterable_attributes(self) -> list[str] | list[FilterableAttributes] | None:
async def get_filterable_attributes(self) -> list[str | FilterableAttributes] | None:
"""Get filterable attributes of the index.

Returns:
Expand All @@ -3616,22 +3616,22 @@ async def get_filterable_attributes(self) -> list[str] | list[FilterableAttribut

response_json = response.json()

if isinstance(response_json[0], str):
return response_json

filterable_attributes = []
filterable_attributes: list[str | FilterableAttributes] = []
for r in response_json:
filterable_attributes.append(
FilterableAttributes(
attribute_patterns=r["attributePatterns"],
features=FilterableAttributeFeatures(**r["features"]),
if isinstance(r, str):
filterable_attributes.append(r)
else:
filterable_attributes.append(
FilterableAttributes(
attribute_patterns=r["attributePatterns"],
features=FilterableAttributeFeatures(**r["features"]),
)
)
)

return filterable_attributes

async def update_filterable_attributes(
self, body: list[str] | list[FilterableAttributes], *, compress: bool = False
self, body: list[str | FilterableAttributes], *, compress: bool = False
) -> TaskInfo:
"""Update filterable attributes of the index.

Expand Down Expand Up @@ -7224,7 +7224,7 @@ def reset_synonyms(self) -> TaskInfo:

return TaskInfo(**response.json())

def get_filterable_attributes(self) -> list[str] | list[FilterableAttributes] | None:
def get_filterable_attributes(self) -> list[str | FilterableAttributes] | None:
"""Get filterable attributes of the index.

Returns:
Expand All @@ -7247,22 +7247,22 @@ def get_filterable_attributes(self) -> list[str] | list[FilterableAttributes] |

response_json = response.json()

if isinstance(response_json[0], str):
return response_json

filterable_attributes = []
filterable_attributes: list[str | FilterableAttributes] = []
for r in response_json:
filterable_attributes.append(
FilterableAttributes(
attribute_patterns=r["attributePatterns"],
features=FilterableAttributeFeatures(**r["features"]),
if isinstance(r, str):
filterable_attributes.append(r)
else:
filterable_attributes.append(
FilterableAttributes(
attribute_patterns=r["attributePatterns"],
features=FilterableAttributeFeatures(**r["features"]),
)
)
)

return filterable_attributes

def update_filterable_attributes(
self, body: list[str] | list[FilterableAttributes], *, compress: bool = False
self, body: list[str | FilterableAttributes], *, compress: bool = False
) -> TaskInfo:
"""Update filterable attributes of the index.

Expand Down
2 changes: 1 addition & 1 deletion meilisearch_python_sdk/models/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class MeilisearchSettings(CamelBase):
synonyms: JsonDict | None = None
stop_words: list[str] | None = None
ranking_rules: list[str] | None = None
filterable_attributes: list[str] | list[FilterableAttributes] | None = None
filterable_attributes: list[str | FilterableAttributes] | None = None
distinct_attribute: str | None = None
searchable_attributes: list[str] | None = None
displayed_attributes: list[str] | None = None
Expand Down
3 changes: 2 additions & 1 deletion tests/test_async_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ async def test_get_filterable_attributes(async_empty_index):
facet_search=True, filter=Filter(equality=True, comparison=False)
),
),
"genre",
],
),
)
Expand All @@ -594,7 +595,7 @@ async def test_update_filterable_attributes(compress, async_empty_index, filtera
response = await index.update_filterable_attributes(filterable_attributes, compress=compress)
await async_wait_for_task(index.http_client, response.task_uid)
response = await index.get_filterable_attributes()
assert sorted(response) == filterable_attributes
assert response == filterable_attributes


@pytest.mark.parametrize(
Expand Down
3 changes: 2 additions & 1 deletion tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ def test_get_filterable_attributes(empty_index):
facet_search=True, filter=Filter(equality=True, comparison=False)
),
),
"genre",
],
),
)
Expand All @@ -582,7 +583,7 @@ def test_update_filterable_attributes(compress, empty_index, filterable_attribut
response = index.update_filterable_attributes(filterable_attributes, compress=compress)
wait_for_task(index.http_client, response.task_uid)
response = index.get_filterable_attributes()
assert sorted(response) == filterable_attributes
assert response == filterable_attributes


@pytest.mark.parametrize(
Expand Down