Skip to content

Rename attributes_for_faceting into filterable_attributes #287

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

Merged
merged 2 commits into from
Jul 19, 2021
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
2 changes: 1 addition & 1 deletion meilisearch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Paths():
stop_words = 'stop-words'
synonyms = 'synonyms'
accept_new_fields = 'accept-new-fields'
attributes_for_faceting = 'attributes-for-faceting'
filterable_attributes = 'filterable-attributes'
dumps = 'dumps'

def __init__(
Expand Down
12 changes: 6 additions & 6 deletions meilisearch/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ def reset_synonyms(self) -> Dict[str, int]:

# ATTRIBUTES FOR FACETING SUB-ROUTES

def get_attributes_for_faceting(self) -> List[str]:
def get_filterable_attributes(self) -> List[str]:
"""
Get attributes for faceting of the index.

Expand All @@ -990,10 +990,10 @@ def get_attributes_for_faceting(self) -> List[str]:
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
"""
return self.http.get(
self.__settings_url_for(self.config.paths.attributes_for_faceting)
self.__settings_url_for(self.config.paths.filterable_attributes)
)

def update_attributes_for_faceting(self, body: List[str]) -> Dict[str, int]:
def update_filterable_attributes(self, body: List[str]) -> Dict[str, int]:
"""
Update attributes for faceting of the index.

Expand All @@ -1014,11 +1014,11 @@ def update_attributes_for_faceting(self, body: List[str]) -> Dict[str, int]:
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
"""
return self.http.post(
self.__settings_url_for(self.config.paths.attributes_for_faceting),
self.__settings_url_for(self.config.paths.filterable_attributes),
body
)

def reset_attributes_for_faceting(self) -> Dict[str, int]:
def reset_filterable_attributes(self) -> Dict[str, int]:
"""Reset attributes for faceting of the index to default values.

Returns
Expand All @@ -1033,7 +1033,7 @@ def reset_attributes_for_faceting(self) -> Dict[str, int]:
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
"""
return self.http.delete(
self.__settings_url_for(self.config.paths.attributes_for_faceting),
self.__settings_url_for(self.config.paths.filterable_attributes),
)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion meilisearch/tests/index/test_index_search_meilisearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def test_custom_search_params_with_string_list(index_with_documents):

def test_custom_search_params_with_facets_distribution(index_with_documents):
index = index_with_documents()
update = index.update_attributes_for_faceting(['genre'])
update = index.update_filterable_attributes(['genre'])
index.wait_for_pending_update(update['updateId'])
response = index.search(
'world',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
# pylint: disable=invalid-name

ATTRIBUTES_FOR_FACETING = ['title', 'release_date']
FILTERABLE_ATTRIBUTES = ['title', 'release_date']

def test_get_attributes_for_faceting(empty_index):
def test_get_filterable_attributes(empty_index):
"""Tests getting the attributes for faceting."""
response = empty_index().get_attributes_for_faceting()
response = empty_index().get_filterable_attributes()
assert isinstance(response, list)
assert response == []

def test_update_attributes_for_faceting(empty_index):
def test_update_filterable_attributes(empty_index):
"""Tests updating the attributes for faceting."""
index = empty_index()
response = index.update_attributes_for_faceting(ATTRIBUTES_FOR_FACETING)
response = index.update_filterable_attributes(FILTERABLE_ATTRIBUTES)
index.wait_for_pending_update(response['updateId'])
get_attributes_new = index.get_attributes_for_faceting()
assert len(get_attributes_new) == len(ATTRIBUTES_FOR_FACETING)
get_attributes = index.get_attributes_for_faceting()
for attribute in ATTRIBUTES_FOR_FACETING:
get_attributes_new = index.get_filterable_attributes()
assert len(get_attributes_new) == len(FILTERABLE_ATTRIBUTES)
get_attributes = index.get_filterable_attributes()
for attribute in FILTERABLE_ATTRIBUTES:
assert attribute in get_attributes

def test_update_attributes_for_faceting_to_none(empty_index):
def test_update_filterable_attributes_to_none(empty_index):
"""Tests updating the attributes for faceting at null."""
index = empty_index()
# Update the settings first
response = index.update_attributes_for_faceting(ATTRIBUTES_FOR_FACETING)
response = index.update_filterable_attributes(FILTERABLE_ATTRIBUTES)
update = index.wait_for_pending_update(response['updateId'])
assert update['status'] == 'processed'
# Check the settings have been correctly updated
get_attributes = index.get_attributes_for_faceting()
for attribute in ATTRIBUTES_FOR_FACETING:
get_attributes = index.get_filterable_attributes()
for attribute in FILTERABLE_ATTRIBUTES:
assert attribute in get_attributes
# Launch test to update at null the setting
response = index.update_attributes_for_faceting(None)
response = index.update_filterable_attributes(None)
index.wait_for_pending_update(response['updateId'])
response = index.get_attributes_for_faceting()
response = index.get_filterable_attributes()
assert response == []

def test_reset_attributes_for_faceting(empty_index):
def test_reset_filterable_attributes(empty_index):
"""Tests resetting the attributes for faceting setting to its default value"""
index = empty_index()
# Update the settings first
response = index.update_attributes_for_faceting(ATTRIBUTES_FOR_FACETING)
response = index.update_filterable_attributes(FILTERABLE_ATTRIBUTES)
update = index.wait_for_pending_update(response['updateId'])
assert update['status'] == 'processed'
# Check the settings have been correctly updated
get_attributes_new = index.get_attributes_for_faceting()
assert len(get_attributes_new) == len(ATTRIBUTES_FOR_FACETING)
get_attributes = index.get_attributes_for_faceting()
for attribute in ATTRIBUTES_FOR_FACETING:
get_attributes_new = index.get_filterable_attributes()
assert len(get_attributes_new) == len(FILTERABLE_ATTRIBUTES)
get_attributes = index.get_filterable_attributes()
for attribute in FILTERABLE_ATTRIBUTES:
assert attribute in get_attributes
# Check the reset of the settings
response = index.reset_attributes_for_faceting()
response = index.reset_filterable_attributes()
assert isinstance(response, dict)
assert 'updateId' in response
index.wait_for_pending_update(response['updateId'])
response = index.get_attributes_for_faceting()
response = index.get_filterable_attributes()
assert isinstance(response, list)
assert response == []