From 90ee4f3ce75a5b41e96bbe51265ccfbb155d6ee1 Mon Sep 17 00:00:00 2001 From: meili-bot <74670311+meili-bot@users.noreply.github.com> Date: Mon, 11 Apr 2022 15:39:39 +0200 Subject: [PATCH 01/20] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6f70b9f8..4089e4a9 100644 --- a/README.md +++ b/README.md @@ -197,7 +197,7 @@ index.search( ## 🤖 Compatibility with Meilisearch -This package only guarantees the compatibility with the [version v0.26.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.26.0). +This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0). ## 💡 Learn More From e459c96d7e8fc0123f81d902fe64e2a32cf11e69 Mon Sep 17 00:00:00 2001 From: meili-bot <74670311+meili-bot@users.noreply.github.com> Date: Mon, 11 Apr 2022 20:10:45 +0200 Subject: [PATCH 02/20] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6e9c5899..5784f664 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,7 +51,7 @@ Optionally tox can be used to run test on all supported version of Python, mypy, ```bash docker pull getmeili/meilisearch:latest # Fetch the latest version of Meilisearch image from Docker Hub -docker run -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey --no-analytics +docker run -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey --no-analytics pipenv run tox ``` From c30b06944e897a0b43ad36a0c7b38e37a794b3c2 Mon Sep 17 00:00:00 2001 From: meili-bot <74670311+meili-bot@users.noreply.github.com> Date: Mon, 11 Apr 2022 20:10:45 +0200 Subject: [PATCH 03/20] Update .github/workflows/tests.yml --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4833c362..743da4df 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,7 +31,7 @@ jobs: - name: Install dependencies run: pipenv install --dev - name: Meilisearch (latest version) setup with Docker - run: docker run -d -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --no-analytics --master-key=masterKey + run: docker run -d -p 7700:7700 getmeili/meilisearch:latest meilisearch --no-analytics --master-key=masterKey - name: Test with pytest run: pipenv run pytest From acd6e142948f277a11066e40f6c326ac3c28ce7d Mon Sep 17 00:00:00 2001 From: meili-bot <74670311+meili-bot@users.noreply.github.com> Date: Mon, 11 Apr 2022 20:10:46 +0200 Subject: [PATCH 04/20] Update .github/workflows/pre-release-tests.yml --- .github/workflows/pre-release-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pre-release-tests.yml b/.github/workflows/pre-release-tests.yml index fc4c8900..7379ba75 100644 --- a/.github/workflows/pre-release-tests.yml +++ b/.github/workflows/pre-release-tests.yml @@ -29,6 +29,6 @@ jobs: - name: Get the latest Meilisearch RC run: echo "MEILISEARCH_VERSION=$(curl https://raw.githubusercontent.com/meilisearch/integration-guides/main/scripts/get-latest-meilisearch-rc.sh | bash)" >> $GITHUB_ENV - name: Meilisearch (${{ env.MEILISEARCH_VERSION }}) setup with Docker - run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} ./meilisearch --master-key=masterKey --no-analytics + run: docker run -d -p 7700:7700 getmeili/meilisearch:${{ env.MEILISEARCH_VERSION }} meilisearch --master-key=masterKey --no-analytics - name: Test with pytest run: pipenv run pytest From 88093dcef10f2b1343ad9e28aa0d1811b617bced Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 20 Apr 2022 10:06:19 +0200 Subject: [PATCH 05/20] Add typo tolerance settings --- meilisearch/config.py | 1 + meilisearch/index.py | 113 ++++++++++++++---- ...est_settings_typo_tolerance_meilisearch.py | 49 ++++++++ 3 files changed, 138 insertions(+), 25 deletions(-) create mode 100644 tests/settings/test_settings_typo_tolerance_meilisearch.py diff --git a/meilisearch/config.py b/meilisearch/config.py index 67a4e566..9b6442be 100644 --- a/meilisearch/config.py +++ b/meilisearch/config.py @@ -25,6 +25,7 @@ class Paths(): accept_new_fields = 'accept-new-fields' filterable_attributes = 'filterable-attributes' sortable_attributes = 'sortable-attributes' + typo_tolerance = 'typo-tolerance' dumps = 'dumps' def __init__( diff --git a/meilisearch/index.py b/meilisearch/index.py index b07dd44b..2b6feb1d 100644 --- a/meilisearch/index.py +++ b/meilisearch/index.py @@ -289,7 +289,7 @@ def add_documents( self, documents: List[Dict[str, Any]], primary_key: Optional[str] = None, - ) -> Dict[str, int]: + ) -> Dict[str, Any]: """Add documents to the index. Parameters @@ -318,7 +318,7 @@ def add_documents_in_batches( documents: List[Dict[str, Any]], batch_size: int = 1000, primary_key: Optional[str] = None, - ) -> List[Dict[str, int]]: + ) -> List[Dict[str, Any]]: """Add documents to the index in batches. Parameters @@ -355,7 +355,7 @@ def add_documents_json( self, str_documents: str, primary_key: Optional[str] = None, - ) -> Dict[str, int]: + ) -> Dict[str, Any]: """Add string documents from JSON file to the index. Parameters @@ -382,7 +382,7 @@ def add_documents_csv( self, str_documents: str, primary_key: Optional[str] = None, - ) -> Dict[str, int]: + ) -> Dict[str, Any]: """Add string documents from a CSV file to the index. Parameters @@ -409,7 +409,7 @@ def add_documents_ndjson( self, str_documents: str, primary_key: Optional[str] = None, - ) -> Dict[str, int]: + ) -> Dict[str, Any]: """Add string documents from a NDJSON file to the index. Parameters @@ -437,7 +437,7 @@ def add_documents_raw( str_documents: str, primary_key: Optional[str] = None, content_type: Optional[str] = None, - ) -> Dict[str, int]: + ) -> Dict[str, Any]: """Add string documents to the index. Parameters @@ -467,7 +467,7 @@ def update_documents( self, documents: List[Dict[str, Any]], primary_key: Optional[str] = None - ) -> Dict[str, int]: + ) -> Dict[str, Any]: """Update documents in the index. Parameters @@ -615,7 +615,7 @@ def get_settings(self) -> Dict[str, Any]: f'{self.config.paths.index}/{self.uid}/{self.config.paths.setting}' ) - def update_settings(self, body: Dict[str, Any]) -> Dict[str, int]: + def update_settings(self, body: Dict[str, Any]) -> Dict[str, Any]: """Update settings of the index. https://docs.meilisearch.com/reference/api/settings.html#update-settings @@ -643,7 +643,7 @@ def update_settings(self, body: Dict[str, Any]) -> Dict[str, int]: body ) - def reset_settings(self) -> Dict[str, int]: + def reset_settings(self) -> Dict[str, Any]: """Reset settings of the index to default values. https://docs.meilisearch.com/reference/api/settings.html#reset-settings @@ -683,7 +683,7 @@ def get_ranking_rules(self) -> List[str]: self.__settings_url_for(self.config.paths.ranking_rules) ) - def update_ranking_rules(self, body: List[str]) -> Dict[str, int]: + def update_ranking_rules(self, body: List[str]) -> Dict[str, Any]: """ Update ranking rules of the index. @@ -708,7 +708,7 @@ def update_ranking_rules(self, body: List[str]) -> Dict[str, int]: body ) - def reset_ranking_rules(self) -> Dict[str, int]: + def reset_ranking_rules(self) -> Dict[str, Any]: """Reset ranking rules of the index to default values. Returns @@ -746,7 +746,7 @@ def get_distinct_attribute(self) -> Optional[str]: self.__settings_url_for(self.config.paths.distinct_attribute) ) - def update_distinct_attribute(self, body: Dict[str, Any]) -> Dict[str, int]: + def update_distinct_attribute(self, body: Dict[str, Any]) -> Dict[str, Any]: """ Update distinct attribute of the index. @@ -771,7 +771,7 @@ def update_distinct_attribute(self, body: Dict[str, Any]) -> Dict[str, int]: body ) - def reset_distinct_attribute(self) -> Dict[str, int]: + def reset_distinct_attribute(self) -> Dict[str, Any]: """Reset distinct attribute of the index to default values. Returns @@ -809,7 +809,7 @@ def get_searchable_attributes(self) -> List[str]: self.__settings_url_for(self.config.paths.searchable_attributes) ) - def update_searchable_attributes(self, body: List[str]) -> Dict[str, int]: + def update_searchable_attributes(self, body: List[str]) -> Dict[str, Any]: """ Update searchable attributes of the index. @@ -834,7 +834,7 @@ def update_searchable_attributes(self, body: List[str]) -> Dict[str, int]: body ) - def reset_searchable_attributes(self) -> Dict[str, int]: + def reset_searchable_attributes(self) -> Dict[str, Any]: """Reset searchable attributes of the index to default values. Returns @@ -872,7 +872,7 @@ def get_displayed_attributes(self) -> List[str]: self.__settings_url_for(self.config.paths.displayed_attributes) ) - def update_displayed_attributes(self, body: List[str]) -> Dict[str, int]: + def update_displayed_attributes(self, body: List[str]) -> Dict[str, Any]: """ Update displayed attributes of the index. @@ -897,7 +897,7 @@ def update_displayed_attributes(self, body: List[str]) -> Dict[str, int]: body ) - def reset_displayed_attributes(self) -> Dict[str, int]: + def reset_displayed_attributes(self) -> Dict[str, Any]: """Reset displayed attributes of the index to default values. Returns @@ -935,7 +935,7 @@ def get_stop_words(self) -> List[str]: self.__settings_url_for(self.config.paths.stop_words) ) - def update_stop_words(self, body: List[str]) -> Dict[str, int]: + def update_stop_words(self, body: List[str]) -> Dict[str, Any]: """ Update stop words of the index. @@ -960,7 +960,7 @@ def update_stop_words(self, body: List[str]) -> Dict[str, int]: body ) - def reset_stop_words(self) -> Dict[str, int]: + def reset_stop_words(self) -> Dict[str, Any]: """Reset stop words of the index to default values. Returns @@ -998,7 +998,7 @@ def get_synonyms(self) -> Dict[str, List[str]]: self.__settings_url_for(self.config.paths.synonyms) ) - def update_synonyms(self, body: Dict[str, List[str]]) -> Dict[str, int]: + def update_synonyms(self, body: Dict[str, List[str]]) -> Dict[str, Any]: """ Update synonyms of the index. @@ -1023,7 +1023,7 @@ def update_synonyms(self, body: Dict[str, List[str]]) -> Dict[str, int]: body ) - def reset_synonyms(self) -> Dict[str, int]: + def reset_synonyms(self) -> Dict[str, Any]: """Reset synonyms of the index to default values. Returns @@ -1061,7 +1061,7 @@ def get_filterable_attributes(self) -> List[str]: self.__settings_url_for(self.config.paths.filterable_attributes) ) - def update_filterable_attributes(self, body: List[str]) -> Dict[str, int]: + def update_filterable_attributes(self, body: List[str]) -> Dict[str, Any]: """ Update filterable attributes of the index. @@ -1086,7 +1086,7 @@ def update_filterable_attributes(self, body: List[str]) -> Dict[str, int]: body ) - def reset_filterable_attributes(self) -> Dict[str, int]: + def reset_filterable_attributes(self) -> Dict[str, Any]: """Reset filterable attributes of the index to default values. Returns @@ -1125,7 +1125,7 @@ def get_sortable_attributes(self) -> List[str]: self.__settings_url_for(self.config.paths.sortable_attributes) ) - def update_sortable_attributes(self, body: List[str]) -> Dict[str, int]: + def update_sortable_attributes(self, body: List[str]) -> Dict[str, Any]: """ Update sortable attributes of the index. @@ -1150,7 +1150,7 @@ def update_sortable_attributes(self, body: List[str]) -> Dict[str, int]: body ) - def reset_sortable_attributes(self) -> Dict[str, int]: + def reset_sortable_attributes(self) -> Dict[str, Any]: """Reset sortable attributes of the index to default values. Returns @@ -1168,6 +1168,69 @@ def reset_sortable_attributes(self) -> Dict[str, int]: self.__settings_url_for(self.config.paths.sortable_attributes), ) + # TYPO TOLERANCE SUB-ROUTES + + def get_typo_tolerance(self) -> Dict[str, Any]: + """ + Get typo tolerance of the index. + + Returns + ------- + settings: dict + Dictionary containing the typo tolerance of the index. + + Raises + ------ + MeiliSearchApiError + 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.typo_tolerance) + ) + + def update_typo_tolerance(self, body: Dict[str, Any]) -> Dict[str, Any]: + """ + Update typo tolerance of the index. + + Parameters + ---------- + body: dict + Dictionary containing the typo tolerance. + + Returns + ------- + task: + Dictionary containing a task to track the informations about the progress of an asynchronous process. + https://docs.meilisearch.com/reference/api/tasks.html#get-one-task + + Raises + ------ + MeiliSearchApiError + 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.typo_tolerance), + body + ) + + def reset_typo_tolerance(self) -> Dict[str, Any]: + """Reset typo tolerance of the index to default values. + + Returns + ------- + task: + Dictionary containing a task to track the informations about the progress of an asynchronous process. + https://docs.meilisearch.com/reference/api/tasks.html#get-one-task + + Raises + ------ + MeiliSearchApiError + 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.typo_tolerance), + ) + @staticmethod def _batch( documents: List[Dict[str, Any]], batch_size: int diff --git a/tests/settings/test_settings_typo_tolerance_meilisearch.py b/tests/settings/test_settings_typo_tolerance_meilisearch.py new file mode 100644 index 00000000..2349561f --- /dev/null +++ b/tests/settings/test_settings_typo_tolerance_meilisearch.py @@ -0,0 +1,49 @@ +TYPO_TOLERANCE = { + 'enabled': 'true', + 'minWordLengthForTypo': { + 'oneTypo': 5, + 'twoTypos': 9, + }, + 'disableOnWords': [], + 'disableOnAttributes': [], +} + +def test_get_typo_tolerance_default(empty_index): + """Tests getting default typo_tolerance.""" + response = empty_index().get_typo_tolerance() + assert isinstance(response, dict) + assert response == {} + +def test_update_typo_tolerance(empty_index): + """Tests updating typo_tolerance.""" + index = empty_index() + response = index.update_typo_tolerance(TYPO_TOLERANCE) + assert isinstance(response, dict) + assert 'uid' in response + update = index.wait_for_task(response['uid']) + assert update['status'] == 'succeeded' + response = index.get_typo_tolerance() + assert isinstance(response, dict) + for typo_tolerance in TYPO_TOLERANCE: + assert typo_tolerance in response + +def test_reset_typo_tolerance(empty_index): + """Tests resetting the typo_tolerance setting to its default value.""" + index = empty_index() + # Update the settings first + response = index.update_typo_tolerance(TYPO_TOLERANCE) + update = index.wait_for_task(response['uid']) + assert update['status'] == 'succeeded' + # Check the settings have been correctly updated + response = index.get_typo_tolerance() + assert isinstance(response, dict) + for typo_tolerance in TYPO_TOLERANCE: + assert typo_tolerance in response + # Check the reset of the settings + response = index.reset_typo_tolerance() + assert isinstance(response, dict) + assert 'uid' in response + update = index.wait_for_task(response['uid']) + assert update['status'] == 'succeeded' + response = index.get_typo_tolerance() + assert response == {} From f0eca613608d93ba2ee3397644a763fb4f083eb4 Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 20 Apr 2022 10:28:12 +0200 Subject: [PATCH 06/20] Fix tests --- ...est_settings_typo_tolerance_meilisearch.py | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/settings/test_settings_typo_tolerance_meilisearch.py b/tests/settings/test_settings_typo_tolerance_meilisearch.py index 2349561f..fe9f7460 100644 --- a/tests/settings/test_settings_typo_tolerance_meilisearch.py +++ b/tests/settings/test_settings_typo_tolerance_meilisearch.py @@ -1,5 +1,5 @@ -TYPO_TOLERANCE = { - 'enabled': 'true', +DEFAUT_TYPO_TOLERANCE = { + 'enabled': True, 'minWordLengthForTypo': { 'oneTypo': 5, 'twoTypos': 9, @@ -8,36 +8,46 @@ 'disableOnAttributes': [], } +NEW_TYPO_TOLERANCE = { + 'enabled': True, + 'minWordLengthForTypo': { + 'oneTypo': 6, + 'twoTypos': 10, + }, + 'disableOnWords': [], + 'disableOnAttributes': ['title'], +} + def test_get_typo_tolerance_default(empty_index): """Tests getting default typo_tolerance.""" response = empty_index().get_typo_tolerance() assert isinstance(response, dict) - assert response == {} + assert response == DEFAUT_TYPO_TOLERANCE def test_update_typo_tolerance(empty_index): """Tests updating typo_tolerance.""" index = empty_index() - response = index.update_typo_tolerance(TYPO_TOLERANCE) + response = index.update_typo_tolerance(NEW_TYPO_TOLERANCE) assert isinstance(response, dict) assert 'uid' in response update = index.wait_for_task(response['uid']) assert update['status'] == 'succeeded' response = index.get_typo_tolerance() assert isinstance(response, dict) - for typo_tolerance in TYPO_TOLERANCE: + for typo_tolerance in NEW_TYPO_TOLERANCE: assert typo_tolerance in response def test_reset_typo_tolerance(empty_index): """Tests resetting the typo_tolerance setting to its default value.""" index = empty_index() # Update the settings first - response = index.update_typo_tolerance(TYPO_TOLERANCE) + response = index.update_typo_tolerance(NEW_TYPO_TOLERANCE) update = index.wait_for_task(response['uid']) assert update['status'] == 'succeeded' # Check the settings have been correctly updated response = index.get_typo_tolerance() assert isinstance(response, dict) - for typo_tolerance in TYPO_TOLERANCE: + for typo_tolerance in NEW_TYPO_TOLERANCE: assert typo_tolerance in response # Check the reset of the settings response = index.reset_typo_tolerance() @@ -46,4 +56,4 @@ def test_reset_typo_tolerance(empty_index): update = index.wait_for_task(response['uid']) assert update['status'] == 'succeeded' response = index.get_typo_tolerance() - assert response == {} + assert response == DEFAUT_TYPO_TOLERANCE From a5efa10a8a70bc01e4a93bd4c3439258dd4b9ef6 Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 20 Apr 2022 11:30:42 +0200 Subject: [PATCH 07/20] Add support nested fields --- datasets/nested_movies.json | 54 ++++++++++++++++++++ tests/conftest.py | 8 +++ tests/index/test_index_search_meilisearch.py | 34 ++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 datasets/nested_movies.json diff --git a/datasets/nested_movies.json b/datasets/nested_movies.json new file mode 100644 index 00000000..68a97335 --- /dev/null +++ b/datasets/nested_movies.json @@ -0,0 +1,54 @@ +[ + { + "id": 1, + "title": "Pride and Prejudice", + "info": { + "comment": "A great book", + "reviewNb": 50 + } + }, + { + "id": 2, + "title": "Le Petit Prince", + "info": { + "comment": "A french book", + "reviewNb": 600 + } + }, + { + "id": 3, + "title": "Le Rouge et le Noir", + "info": { + "comment": "Another french book", + "reviewNb": 700 + } + }, + { + "id": 4, + "title": "Alice In Wonderland", + "comment": "A weird book", + "info": { + "comment": "A weird book", + "reviewNb": 800 + } + }, + { + "id": 5, + "title": "The Hobbit", + "info": { + "comment": "An awesome book", + "reviewNb": 900 + } + }, + { + "id": 6, + "title": "Harry Potter and the Half-Blood Prince", + "info": { + "comment": "The best book", + "reviewNb": 1000 + } + }, + { "id": 7, + "title": "The Hitchhiker's Guide to the Galaxy" + } +] diff --git a/tests/conftest.py b/tests/conftest.py index 43124544..37f9dbb8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -67,6 +67,14 @@ def songs_ndjson(): with open('./datasets/songs.ndjson', 'r', encoding='utf-8') as song_ndjson_file: return song_ndjson_file.read().encode('utf-8') +@fixture(scope='session') +def nested_movies(): + """ + Runs once per session. Provides the content of nested_movies.json. + """ + with open('./datasets/nested_movies.json', 'r', encoding='utf-8') as nested_movie_file: + yield json.loads(nested_movie_file.read()) + @fixture(scope='function') def empty_index(client, index_uid: Optional[str] = None): index_uid = index_uid if index_uid else common.INDEX_UID diff --git a/tests/index/test_index_search_meilisearch.py b/tests/index/test_index_search_meilisearch.py index 9886c908..7cbdafd2 100644 --- a/tests/index/test_index_search_meilisearch.py +++ b/tests/index/test_index_search_meilisearch.py @@ -350,3 +350,37 @@ def test_phrase_search(index_with_documents): assert 'release_date' in response['hits'][0] assert response['hits'][0]['title'] == 'Dumbo' assert '_formatted' not in response['hits'][0] + +def test_basic_search_on_nested_documents(index_with_documents, nested_movies): + """Tests search with an simple query on nested fields.""" + response = index_with_documents('nested_fields_index', nested_movies).search('An awesome') + assert isinstance(response, dict) + assert response['hits'][0]['id'] == 5 + assert len(response['hits']) == 1 + +def test_search_on_nested_documents_with_searchable_attributes(index_with_documents, nested_movies): + """Tests search on nested fields with searchable attribute.""" + index = index_with_documents('nested_fields_index', nested_movies) + response_searchable_attributes = index.update_searchable_attributes(['title', 'info.comment']) + index.wait_for_task(response_searchable_attributes['uid']) + response = index.search('An awesome') + assert isinstance(response, dict) + assert response['hits'][0]['id'] == 5 + assert len(response['hits']) == 1 + +def test_search_on_nested_documents_with_sortable_attributes(index_with_documents, nested_movies): + """Tests search on nested fields with searchable attribute and sortable attributes.""" + index = index_with_documents('nested_fields_index', nested_movies) + response_settings = index.update_settings({ + 'searchableAttributes': ['title', 'info.comment'], + 'sortableAttributes': ['info.reviewNb'], + }) + index.wait_for_task(response_settings['uid']) + response = index.search( + '', + { + 'sort': ['info.reviewNb:desc'] + } + ) + assert isinstance(response, dict) + assert response['hits'][0]['id'] == 6 From cfbc532d624e40b992329163302364e5df5b3dc2 Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 20 Apr 2022 13:23:31 +0200 Subject: [PATCH 08/20] Add tests for cropping and highlighting --- tests/index/test_index_search_meilisearch.py | 66 ++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/index/test_index_search_meilisearch.py b/tests/index/test_index_search_meilisearch.py index 9886c908..578dd683 100644 --- a/tests/index/test_index_search_meilisearch.py +++ b/tests/index/test_index_search_meilisearch.py @@ -113,6 +113,72 @@ def test_custom_search_params_with_string_list(index_with_documents): assert 'title' in response['hits'][0]['_formatted'] assert 'overview' in response['hits'][0]['_formatted'] +def test_custom_search_params_with_crop_marker(index_with_documents): + """Tests search with a list of one string in query params.""" + response = index_with_documents().search( + 'dragon', + { + 'limit': 1, + 'attributesToCrop': ['overview'], + 'cropLength': 10, + } + ) + assert isinstance(response, dict) + assert len(response['hits']) == 1 + assert '_formatted' in response['hits'][0] + assert 'overview' in response['hits'][0]['_formatted'] + assert response['hits'][0]['_formatted']['overview'].count(' ') < 10 + assert response['hits'][0]['_formatted']['overview'].count('…') == 2 + +def test_custom_search_params_with_customized_crop_marker(index_with_documents): + """Tests search with a list of one string in query params.""" + response = index_with_documents().search( + 'dragon', + { + 'limit': 1, + 'attributesToCrop': ['overview'], + 'cropLength': 10, + 'cropMarker': '(ꈍᴗꈍ)', + } + ) + assert isinstance(response, dict) + assert len(response['hits']) == 1 + assert '_formatted' in response['hits'][0] + assert 'overview' in response['hits'][0]['_formatted'] + assert response['hits'][0]['_formatted']['overview'].count('(ꈍᴗꈍ)') == 2 + +def test_custom_search_params_with_highlight_tag(index_with_documents): + """Tests search with a list of one string in query params.""" + response = index_with_documents().search( + 'dragon', + { + 'limit': 1, + 'attributesToHighlight': ['*'], + } + ) + assert isinstance(response, dict) + assert len(response['hits']) == 1 + assert '_formatted' in response['hits'][0] + assert 'title' in response['hits'][0]['_formatted'] + assert response['hits'][0]['_formatted']['title'] == 'How to Train Your Dragon: The Hidden World' + +def test_custom_search_params_with_customized_highlight_tag(index_with_documents): + """Tests search with a list of one string in query params.""" + response = index_with_documents().search( + 'dragon', + { + 'limit': 1, + 'attributesToHighlight': ['*'], + 'highlightPreTag': '(⊃。•́‿•̀。)⊃ ', + 'highlightPostTag': ' ⊂(´• ω •`⊂)', + } + ) + assert isinstance(response, dict) + assert len(response['hits']) == 1 + assert '_formatted' in response['hits'][0] + assert 'title' in response['hits'][0]['_formatted'] + assert response['hits'][0]['_formatted']['title'] == 'How to Train Your (⊃。•́‿•̀。)⊃ Dragon ⊂(´• ω •`⊂): The Hidden World' + def test_custom_search_params_with_facets_distribution(index_with_documents): index = index_with_documents() update = index.update_filterable_attributes(['genre']) From db06fc6d4cb63182c24ddb9fd4e16ef86c036656 Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 21 Apr 2022 11:31:25 +0200 Subject: [PATCH 09/20] Fix field naming in typo tolerance --- tests/settings/test_settings_typo_tolerance_meilisearch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/settings/test_settings_typo_tolerance_meilisearch.py b/tests/settings/test_settings_typo_tolerance_meilisearch.py index fe9f7460..ac4fdde2 100644 --- a/tests/settings/test_settings_typo_tolerance_meilisearch.py +++ b/tests/settings/test_settings_typo_tolerance_meilisearch.py @@ -1,6 +1,6 @@ DEFAUT_TYPO_TOLERANCE = { 'enabled': True, - 'minWordLengthForTypo': { + 'minWordSizeForTypos': { 'oneTypo': 5, 'twoTypos': 9, }, @@ -10,7 +10,7 @@ NEW_TYPO_TOLERANCE = { 'enabled': True, - 'minWordLengthForTypo': { + 'minWordSizeForTypos': { 'oneTypo': 6, 'twoTypos': 10, }, @@ -23,6 +23,7 @@ def test_get_typo_tolerance_default(empty_index): response = empty_index().get_typo_tolerance() assert isinstance(response, dict) assert response == DEFAUT_TYPO_TOLERANCE + print(response) def test_update_typo_tolerance(empty_index): """Tests updating typo_tolerance.""" From 336e548f8c2d5a94cf0515553cb52a38b5f1ccfa Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 21 Apr 2022 18:45:26 +0200 Subject: [PATCH 10/20] Trigger Build From 21b221bf4c0d22dec7a0b0613f89d62c26c86ea1 Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 25 Apr 2022 15:25:34 +0200 Subject: [PATCH 11/20] Add typo tolerance check in general settings tests --- tests/settings/test_settings.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/settings/test_settings.py b/tests/settings/test_settings.py index 6a0021ec..83596c58 100644 --- a/tests/settings/test_settings.py +++ b/tests/settings/test_settings.py @@ -13,12 +13,24 @@ 'exactness' ] +DEFAUT_TYPO_TOLERANCE = { + 'enabled': True, + 'minWordSizeForTypos': { + 'oneTypo': 5, + 'twoTypos': 9, + }, + 'disableOnWords': [], + 'disableOnAttributes': [], +} + def test_get_settings_default(empty_index): """Tests getting all settings by default.""" response = empty_index().get_settings() assert isinstance(response, dict) for rule in DEFAULT_RANKING_RULES: assert rule in response['rankingRules'] + for typo in DEFAUT_TYPO_TOLERANCE: + assert typo in response['typoTolerance'] assert response['distinctAttribute'] is None assert response['searchableAttributes'] == ['*'] assert response['displayedAttributes'] == ['*'] @@ -69,6 +81,8 @@ def test_reset_settings(empty_index): response = index.get_settings() for rule in DEFAULT_RANKING_RULES: assert rule in response['rankingRules'] + for typo in DEFAUT_TYPO_TOLERANCE: + assert typo in response['typoTolerance'] assert response['distinctAttribute'] is None assert response['displayedAttributes'] == ['*'] assert response['searchableAttributes'] == ['*'] From b17f1a88e6341327f73fa35d9cee56e255cdcf69 Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 25 Apr 2022 17:03:56 +0200 Subject: [PATCH 12/20] Typo --- meilisearch/index.py | 54 +++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 36 deletions(-) diff --git a/meilisearch/index.py b/meilisearch/index.py index 2b6feb1d..0240f925 100644 --- a/meilisearch/index.py +++ b/meilisearch/index.py @@ -666,8 +666,7 @@ def reset_settings(self) -> Dict[str, Any]: # RANKING RULES SUB-ROUTES def get_ranking_rules(self) -> List[str]: - """ - Get ranking rules of the index. + """Get ranking rules of the index. Returns ------- @@ -684,8 +683,7 @@ def get_ranking_rules(self) -> List[str]: ) def update_ranking_rules(self, body: List[str]) -> Dict[str, Any]: - """ - Update ranking rules of the index. + """Update ranking rules of the index. Parameters ---------- @@ -729,8 +727,7 @@ def reset_ranking_rules(self) -> Dict[str, Any]: # DISTINCT ATTRIBUTE SUB-ROUTES def get_distinct_attribute(self) -> Optional[str]: - """ - Get distinct attribute of the index. + """Get distinct attribute of the index. Returns ------- @@ -747,8 +744,7 @@ def get_distinct_attribute(self) -> Optional[str]: ) def update_distinct_attribute(self, body: Dict[str, Any]) -> Dict[str, Any]: - """ - Update distinct attribute of the index. + """Update distinct attribute of the index. Parameters ---------- @@ -792,8 +788,7 @@ def reset_distinct_attribute(self) -> Dict[str, Any]: # SEARCHABLE ATTRIBUTES SUB-ROUTES def get_searchable_attributes(self) -> List[str]: - """ - Get searchable attributes of the index. + """Get searchable attributes of the index. Returns ------- @@ -810,8 +805,7 @@ def get_searchable_attributes(self) -> List[str]: ) def update_searchable_attributes(self, body: List[str]) -> Dict[str, Any]: - """ - Update searchable attributes of the index. + """Update searchable attributes of the index. Parameters ---------- @@ -855,8 +849,7 @@ def reset_searchable_attributes(self) -> Dict[str, Any]: # DISPLAYED ATTRIBUTES SUB-ROUTES def get_displayed_attributes(self) -> List[str]: - """ - Get displayed attributes of the index. + """Get displayed attributes of the index. Returns ------- @@ -873,8 +866,7 @@ def get_displayed_attributes(self) -> List[str]: ) def update_displayed_attributes(self, body: List[str]) -> Dict[str, Any]: - """ - Update displayed attributes of the index. + """Update displayed attributes of the index. Parameters ---------- @@ -918,8 +910,7 @@ def reset_displayed_attributes(self) -> Dict[str, Any]: # STOP WORDS SUB-ROUTES def get_stop_words(self) -> List[str]: - """ - Get stop words of the index. + """Get stop words of the index. Returns ------- @@ -936,8 +927,7 @@ def get_stop_words(self) -> List[str]: ) def update_stop_words(self, body: List[str]) -> Dict[str, Any]: - """ - Update stop words of the index. + """Update stop words of the index. Parameters ---------- @@ -981,8 +971,7 @@ def reset_stop_words(self) -> Dict[str, Any]: # SYNONYMS SUB-ROUTES def get_synonyms(self) -> Dict[str, List[str]]: - """ - Get synonyms of the index. + """Get synonyms of the index. Returns ------- @@ -999,8 +988,7 @@ def get_synonyms(self) -> Dict[str, List[str]]: ) def update_synonyms(self, body: Dict[str, List[str]]) -> Dict[str, Any]: - """ - Update synonyms of the index. + """Update synonyms of the index. Parameters ---------- @@ -1044,8 +1032,7 @@ def reset_synonyms(self) -> Dict[str, Any]: # FILTERABLE ATTRIBUTES SUB-ROUTES def get_filterable_attributes(self) -> List[str]: - """ - Get filterable attributes of the index. + """Get filterable attributes of the index. Returns ------- @@ -1062,8 +1049,7 @@ def get_filterable_attributes(self) -> List[str]: ) def update_filterable_attributes(self, body: List[str]) -> Dict[str, Any]: - """ - Update filterable attributes of the index. + """Update filterable attributes of the index. Parameters ---------- @@ -1108,8 +1094,7 @@ def reset_filterable_attributes(self) -> Dict[str, Any]: # SORTABLE ATTRIBUTES SUB-ROUTES def get_sortable_attributes(self) -> List[str]: - """ - Get sortable attributes of the index. + """Get sortable attributes of the index. Returns ------- @@ -1126,8 +1111,7 @@ def get_sortable_attributes(self) -> List[str]: ) def update_sortable_attributes(self, body: List[str]) -> Dict[str, Any]: - """ - Update sortable attributes of the index. + """Update sortable attributes of the index. Parameters ---------- @@ -1171,8 +1155,7 @@ def reset_sortable_attributes(self) -> Dict[str, Any]: # TYPO TOLERANCE SUB-ROUTES def get_typo_tolerance(self) -> Dict[str, Any]: - """ - Get typo tolerance of the index. + """Get typo tolerance of the index. Returns ------- @@ -1189,8 +1172,7 @@ def get_typo_tolerance(self) -> Dict[str, Any]: ) def update_typo_tolerance(self, body: Dict[str, Any]) -> Dict[str, Any]: - """ - Update typo tolerance of the index. + """Update typo tolerance of the index. Parameters ---------- From 1530d5e7fec911d0cf8a0c2790251a53d35dd2fb Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 25 Apr 2022 17:50:22 +0200 Subject: [PATCH 13/20] Correct defaut by default --- tests/settings/test_settings.py | 6 +++--- tests/settings/test_settings_typo_tolerance_meilisearch.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/settings/test_settings.py b/tests/settings/test_settings.py index 83596c58..446653b2 100644 --- a/tests/settings/test_settings.py +++ b/tests/settings/test_settings.py @@ -13,7 +13,7 @@ 'exactness' ] -DEFAUT_TYPO_TOLERANCE = { +DEFAULT_TYPO_TOLERANCE = { 'enabled': True, 'minWordSizeForTypos': { 'oneTypo': 5, @@ -29,7 +29,7 @@ def test_get_settings_default(empty_index): assert isinstance(response, dict) for rule in DEFAULT_RANKING_RULES: assert rule in response['rankingRules'] - for typo in DEFAUT_TYPO_TOLERANCE: + for typo in DEFAULT_TYPO_TOLERANCE: assert typo in response['typoTolerance'] assert response['distinctAttribute'] is None assert response['searchableAttributes'] == ['*'] @@ -81,7 +81,7 @@ def test_reset_settings(empty_index): response = index.get_settings() for rule in DEFAULT_RANKING_RULES: assert rule in response['rankingRules'] - for typo in DEFAUT_TYPO_TOLERANCE: + for typo in DEFAULT_TYPO_TOLERANCE: assert typo in response['typoTolerance'] assert response['distinctAttribute'] is None assert response['displayedAttributes'] == ['*'] diff --git a/tests/settings/test_settings_typo_tolerance_meilisearch.py b/tests/settings/test_settings_typo_tolerance_meilisearch.py index ac4fdde2..9c4c539a 100644 --- a/tests/settings/test_settings_typo_tolerance_meilisearch.py +++ b/tests/settings/test_settings_typo_tolerance_meilisearch.py @@ -1,4 +1,4 @@ -DEFAUT_TYPO_TOLERANCE = { +DEFAULT_TYPO_TOLERANCE = { 'enabled': True, 'minWordSizeForTypos': { 'oneTypo': 5, @@ -22,7 +22,7 @@ def test_get_typo_tolerance_default(empty_index): """Tests getting default typo_tolerance.""" response = empty_index().get_typo_tolerance() assert isinstance(response, dict) - assert response == DEFAUT_TYPO_TOLERANCE + assert response == DEFAULT_TYPO_TOLERANCE print(response) def test_update_typo_tolerance(empty_index): @@ -57,4 +57,4 @@ def test_reset_typo_tolerance(empty_index): update = index.wait_for_task(response['uid']) assert update['status'] == 'succeeded' response = index.get_typo_tolerance() - assert response == DEFAUT_TYPO_TOLERANCE + assert response == DEFAULT_TYPO_TOLERANCE From 96cbf24fd85086edca7eed5f349b6e0d1060bd09 Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 25 Apr 2022 18:04:01 +0200 Subject: [PATCH 14/20] Add test to check the value in typo tolerance setting --- tests/settings/test_settings.py | 2 ++ tests/settings/test_settings_typo_tolerance_meilisearch.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/settings/test_settings.py b/tests/settings/test_settings.py index 446653b2..b55b049f 100644 --- a/tests/settings/test_settings.py +++ b/tests/settings/test_settings.py @@ -31,6 +31,7 @@ def test_get_settings_default(empty_index): assert rule in response['rankingRules'] for typo in DEFAULT_TYPO_TOLERANCE: assert typo in response['typoTolerance'] + assert DEFAULT_TYPO_TOLERANCE.get(typo) == response['typoTolerance'][typo] assert response['distinctAttribute'] is None assert response['searchableAttributes'] == ['*'] assert response['displayedAttributes'] == ['*'] @@ -83,6 +84,7 @@ def test_reset_settings(empty_index): assert rule in response['rankingRules'] for typo in DEFAULT_TYPO_TOLERANCE: assert typo in response['typoTolerance'] + assert DEFAULT_TYPO_TOLERANCE.get(typo) == response['typoTolerance'][typo] assert response['distinctAttribute'] is None assert response['displayedAttributes'] == ['*'] assert response['searchableAttributes'] == ['*'] diff --git a/tests/settings/test_settings_typo_tolerance_meilisearch.py b/tests/settings/test_settings_typo_tolerance_meilisearch.py index 9c4c539a..fb999a5e 100644 --- a/tests/settings/test_settings_typo_tolerance_meilisearch.py +++ b/tests/settings/test_settings_typo_tolerance_meilisearch.py @@ -37,6 +37,7 @@ def test_update_typo_tolerance(empty_index): assert isinstance(response, dict) for typo_tolerance in NEW_TYPO_TOLERANCE: assert typo_tolerance in response + assert NEW_TYPO_TOLERANCE.get(typo_tolerance) == response[typo_tolerance] def test_reset_typo_tolerance(empty_index): """Tests resetting the typo_tolerance setting to its default value.""" @@ -50,6 +51,7 @@ def test_reset_typo_tolerance(empty_index): assert isinstance(response, dict) for typo_tolerance in NEW_TYPO_TOLERANCE: assert typo_tolerance in response + assert NEW_TYPO_TOLERANCE.get(typo_tolerance) == response[typo_tolerance] # Check the reset of the settings response = index.reset_typo_tolerance() assert isinstance(response, dict) From 91b4265ac2061b2bda9088d6cb755c7ad5fdadcd Mon Sep 17 00:00:00 2001 From: alallema Date: Mon, 25 Apr 2022 20:08:35 +0200 Subject: [PATCH 15/20] Improve tests typo tolerance --- tests/settings/test_settings.py | 4 ++-- tests/settings/test_settings_typo_tolerance_meilisearch.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/settings/test_settings.py b/tests/settings/test_settings.py index b55b049f..ada47012 100644 --- a/tests/settings/test_settings.py +++ b/tests/settings/test_settings.py @@ -31,7 +31,7 @@ def test_get_settings_default(empty_index): assert rule in response['rankingRules'] for typo in DEFAULT_TYPO_TOLERANCE: assert typo in response['typoTolerance'] - assert DEFAULT_TYPO_TOLERANCE.get(typo) == response['typoTolerance'][typo] + assert DEFAULT_TYPO_TOLERANCE[typo] == response['typoTolerance'][typo] assert response['distinctAttribute'] is None assert response['searchableAttributes'] == ['*'] assert response['displayedAttributes'] == ['*'] @@ -84,7 +84,7 @@ def test_reset_settings(empty_index): assert rule in response['rankingRules'] for typo in DEFAULT_TYPO_TOLERANCE: assert typo in response['typoTolerance'] - assert DEFAULT_TYPO_TOLERANCE.get(typo) == response['typoTolerance'][typo] + assert DEFAULT_TYPO_TOLERANCE[typo] == response['typoTolerance'][typo] assert response['distinctAttribute'] is None assert response['displayedAttributes'] == ['*'] assert response['searchableAttributes'] == ['*'] diff --git a/tests/settings/test_settings_typo_tolerance_meilisearch.py b/tests/settings/test_settings_typo_tolerance_meilisearch.py index fb999a5e..39f378bd 100644 --- a/tests/settings/test_settings_typo_tolerance_meilisearch.py +++ b/tests/settings/test_settings_typo_tolerance_meilisearch.py @@ -23,7 +23,6 @@ def test_get_typo_tolerance_default(empty_index): response = empty_index().get_typo_tolerance() assert isinstance(response, dict) assert response == DEFAULT_TYPO_TOLERANCE - print(response) def test_update_typo_tolerance(empty_index): """Tests updating typo_tolerance.""" @@ -37,7 +36,7 @@ def test_update_typo_tolerance(empty_index): assert isinstance(response, dict) for typo_tolerance in NEW_TYPO_TOLERANCE: assert typo_tolerance in response - assert NEW_TYPO_TOLERANCE.get(typo_tolerance) == response[typo_tolerance] + assert NEW_TYPO_TOLERANCE[typo_tolerance] == response[typo_tolerance] def test_reset_typo_tolerance(empty_index): """Tests resetting the typo_tolerance setting to its default value.""" @@ -51,7 +50,7 @@ def test_reset_typo_tolerance(empty_index): assert isinstance(response, dict) for typo_tolerance in NEW_TYPO_TOLERANCE: assert typo_tolerance in response - assert NEW_TYPO_TOLERANCE.get(typo_tolerance) == response[typo_tolerance] + assert NEW_TYPO_TOLERANCE[typo_tolerance] == response[typo_tolerance] # Check the reset of the settings response = index.reset_typo_tolerance() assert isinstance(response, dict) From b45b004cb43f5c3ee3de784a601990cf3c15453a Mon Sep 17 00:00:00 2001 From: alallema Date: Wed, 27 Apr 2022 16:33:29 +0200 Subject: [PATCH 16/20] Updateing code-sample for v0.27.0 --- .code-samples.meilisearch.yaml | 63 ++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index 226a7081..dbf92344 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -109,7 +109,13 @@ update_settings_1: |- 'wolverine': ['xmen', 'logan'], 'logan': ['wolverine'] }, - 'acceptNewFields': False + 'typoTolerance': { + 'minWordSizeForTypos': { + 'oneTypo': 8, + 'twoTypos': 10 + }, + 'disableOnAttributes': ['title'] + } }) reset_settings_1: |- client.index('movies').reset_settings() @@ -180,6 +186,20 @@ update_displayed_attributes_1: |- ]) reset_displayed_attributes_1: |- client.index('movies').reset_displayed_attributes() +get_typo_tolerance_1: + client.index('books').get_typo_tolerance() +update_typo_tolerance_1: |- + client.index('books').update_typo_tolerance({ + 'minWordSizeForTypos': { + 'oneTypo': 4, + 'twoTypos': 10 + }, + 'disableOnAttributes': [ + 'title' + ] + }) +reset_typo_tolerance_1: |- + client.index('books').reset_typo_tolerance() get_sortable_attributes_1: |- client.index('books').get_sortable_attributes() update_sortable_attributes_1: |- @@ -243,12 +263,23 @@ search_parameter_guide_retrieve_1: |- search_parameter_guide_crop_1: |- client.index('movies').search('shifu', { 'attributesToCrop': ['overview'], - 'cropLength': 10 + 'cropLength': 5 + }) +search_parameter_guide_crop_marker_1: |- + client.index('movies').search('shifu', { + 'attributesToCrop': ['overview'], + 'cropMarker': '[…]' }) search_parameter_guide_highlight_1: |- client.index('movies').search('winter feast', { 'attributesToHighlight': ['overview'] }) +search_parameter_guide_highlight_tag_1: |- + client.index('movies').search('winter feast', { + 'attributesToHighlight': ['overview'], + 'highlightPreTag': '', + 'highlightPostTag': '' + }) search_parameter_guide_matches_1: |- client.index('movies').search('winter feast', { 'matches': 'true' @@ -309,6 +340,34 @@ settings_guide_sortable_1: |- 'author' ] }) +settings_guide_typo_tolerance_1: |- + client.index('movies').update_typo_tolerance({ + 'minWordSizeForTypos': { + 'twoTypos': 12 + }, + 'disableOnAttributes': [ + 'title' + ] + }) +typo_tolerance_guide_1: |- + client.index('movies').update_typo_tolerance({ + 'enabled': False + }) +typo_tolerance_guide_2: |- + client.index('movies').update_typo_tolerance({ + 'disableOnAttributes': ['title'] + }) +typo_tolerance_guide_3: |- + client.index('movies').update_typo_tolerance({ + 'disableOnWords': ['shrek'] + }) +typo_tolerance_guide_4: |- + client.index('movies').update_typo_tolerance({ + 'minWordSizeForTypos': { + 'oneTypo': 4, + 'twoTypos': 10 + } + }) add_movies_json_1: |- import json From 9f6c48a46d016890e029a39c36715e8dd0a329e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Thu, 28 Apr 2022 00:33:53 +0200 Subject: [PATCH 17/20] Update .code-samples.meilisearch.yaml Co-authored-by: Bruno Casali --- .code-samples.meilisearch.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index dbf92344..d6b5011a 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -277,7 +277,7 @@ search_parameter_guide_highlight_1: |- search_parameter_guide_highlight_tag_1: |- client.index('movies').search('winter feast', { 'attributesToHighlight': ['overview'], - 'highlightPreTag': '', + 'highlightPreTag': '', 'highlightPostTag': '' }) search_parameter_guide_matches_1: |- From cb7f921a15331a2b618e56eb0eb14cf8e613e225 Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 28 Apr 2022 11:46:38 +0200 Subject: [PATCH 18/20] Add space to tests for readability --- .../test_settings_typo_tolerance_meilisearch.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/settings/test_settings_typo_tolerance_meilisearch.py b/tests/settings/test_settings_typo_tolerance_meilisearch.py index 39f378bd..3ccd07d5 100644 --- a/tests/settings/test_settings_typo_tolerance_meilisearch.py +++ b/tests/settings/test_settings_typo_tolerance_meilisearch.py @@ -21,18 +21,25 @@ def test_get_typo_tolerance_default(empty_index): """Tests getting default typo_tolerance.""" response = empty_index().get_typo_tolerance() + assert isinstance(response, dict) assert response == DEFAULT_TYPO_TOLERANCE def test_update_typo_tolerance(empty_index): """Tests updating typo_tolerance.""" index = empty_index() + response = index.update_typo_tolerance(NEW_TYPO_TOLERANCE) + assert isinstance(response, dict) assert 'uid' in response + update = index.wait_for_task(response['uid']) + assert update['status'] == 'succeeded' + response = index.get_typo_tolerance() + assert isinstance(response, dict) for typo_tolerance in NEW_TYPO_TOLERANCE: assert typo_tolerance in response @@ -41,21 +48,31 @@ def test_update_typo_tolerance(empty_index): def test_reset_typo_tolerance(empty_index): """Tests resetting the typo_tolerance setting to its default value.""" index = empty_index() + # Update the settings first response = index.update_typo_tolerance(NEW_TYPO_TOLERANCE) update = index.wait_for_task(response['uid']) + assert update['status'] == 'succeeded' + # Check the settings have been correctly updated response = index.get_typo_tolerance() + assert isinstance(response, dict) for typo_tolerance in NEW_TYPO_TOLERANCE: assert typo_tolerance in response assert NEW_TYPO_TOLERANCE[typo_tolerance] == response[typo_tolerance] + # Check the reset of the settings response = index.reset_typo_tolerance() + assert isinstance(response, dict) assert 'uid' in response + update = index.wait_for_task(response['uid']) + assert update['status'] == 'succeeded' + response = index.get_typo_tolerance() + assert response == DEFAULT_TYPO_TOLERANCE From e8f075aebcc11f64a290bcb4c941751f3ac343e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Am=C3=A9lie?= Date: Thu, 28 Apr 2022 14:51:23 +0200 Subject: [PATCH 19/20] Update .code-samples.meilisearch.yaml Co-authored-by: cvermand <33010418+bidoubiwa@users.noreply.github.com> --- .code-samples.meilisearch.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.code-samples.meilisearch.yaml b/.code-samples.meilisearch.yaml index d6b5011a..1f7ba884 100644 --- a/.code-samples.meilisearch.yaml +++ b/.code-samples.meilisearch.yaml @@ -195,8 +195,8 @@ update_typo_tolerance_1: |- 'twoTypos': 10 }, 'disableOnAttributes': [ - 'title' - ] + 'title' + ] }) reset_typo_tolerance_1: |- client.index('books').reset_typo_tolerance() From 9d008a7ca485160c2e22e83fb956245db2094569 Mon Sep 17 00:00:00 2001 From: alallema Date: Thu, 28 Apr 2022 16:28:01 +0200 Subject: [PATCH 20/20] Improve test readability --- ...est_settings_typo_tolerance_meilisearch.py | 66 ++++++++----------- 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/tests/settings/test_settings_typo_tolerance_meilisearch.py b/tests/settings/test_settings_typo_tolerance_meilisearch.py index 3ccd07d5..612645fb 100644 --- a/tests/settings/test_settings_typo_tolerance_meilisearch.py +++ b/tests/settings/test_settings_typo_tolerance_meilisearch.py @@ -28,51 +28,39 @@ def test_get_typo_tolerance_default(empty_index): def test_update_typo_tolerance(empty_index): """Tests updating typo_tolerance.""" index = empty_index() + response_update = index.update_typo_tolerance(NEW_TYPO_TOLERANCE) + update = index.wait_for_task(response_update['uid']) + response_get = index.get_typo_tolerance() - response = index.update_typo_tolerance(NEW_TYPO_TOLERANCE) - - assert isinstance(response, dict) - assert 'uid' in response - - update = index.wait_for_task(response['uid']) - + assert isinstance(response_update, dict) + assert 'uid' in response_update assert update['status'] == 'succeeded' - - response = index.get_typo_tolerance() - - assert isinstance(response, dict) + assert isinstance(response_get, dict) for typo_tolerance in NEW_TYPO_TOLERANCE: - assert typo_tolerance in response - assert NEW_TYPO_TOLERANCE[typo_tolerance] == response[typo_tolerance] + assert typo_tolerance in response_get + assert NEW_TYPO_TOLERANCE[typo_tolerance] == response_get[typo_tolerance] def test_reset_typo_tolerance(empty_index): """Tests resetting the typo_tolerance setting to its default value.""" index = empty_index() - # Update the settings first - response = index.update_typo_tolerance(NEW_TYPO_TOLERANCE) - update = index.wait_for_task(response['uid']) - - assert update['status'] == 'succeeded' - - # Check the settings have been correctly updated - response = index.get_typo_tolerance() - - assert isinstance(response, dict) + # Update the settings + response_update = index.update_typo_tolerance(NEW_TYPO_TOLERANCE) + update1 = index.wait_for_task(response_update['uid']) + # Get the setting after update + response_get = index.get_typo_tolerance() + # Reset the setting + response_reset = index.reset_typo_tolerance() + update2 = index.wait_for_task(response_reset['uid']) + # Get the setting after reset + response_last = index.get_typo_tolerance() + + assert update1['status'] == 'succeeded' + assert isinstance(response_get, dict) for typo_tolerance in NEW_TYPO_TOLERANCE: - assert typo_tolerance in response - assert NEW_TYPO_TOLERANCE[typo_tolerance] == response[typo_tolerance] - - # Check the reset of the settings - response = index.reset_typo_tolerance() - - assert isinstance(response, dict) - assert 'uid' in response - - update = index.wait_for_task(response['uid']) - - assert update['status'] == 'succeeded' - - response = index.get_typo_tolerance() - - assert response == DEFAULT_TYPO_TOLERANCE + assert typo_tolerance in response_get + assert NEW_TYPO_TOLERANCE[typo_tolerance] == response_get[typo_tolerance] + assert isinstance(response_reset, dict) + assert 'uid' in response_reset + assert update2['status'] == 'succeeded' + assert response_last == DEFAULT_TYPO_TOLERANCE