From 27b7cb38a3c6811fb80f712a5e1bb3041557d998 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 31 Oct 2018 11:21:31 +0100 Subject: [PATCH 1/5] Adds move on the index --- algoliasearch/index.py | 20 ++++++++++++++++++-- tests/test_index.py | 21 +++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/algoliasearch/index.py b/algoliasearch/index.py index b391b58e6..02b7f5d90 100644 --- a/algoliasearch/index.py +++ b/algoliasearch/index.py @@ -311,6 +311,22 @@ def delete_objects(self, objects, request_options=None): }) return self.batch(requests, request_options=request_options) + def move(self, new_index_name, request_options=None): + """ + Move the index. + + @param new_index_name the new name of the + index (destination will be overriten if it already exist). + """ + request = {'operation': 'move', 'destination': new_index_name} + + res = self._req(False, '/operation', 'POST', request_options, data=request) + + self.index_name = new_index_name + self._request_path = '/1/indexes/%s' % safe(self.index_name) + + return res + def search(self, query, args=None, request_options=None): """ Search inside the index. @@ -699,7 +715,7 @@ def iter_synonyms(self, hits_per_page=1000, request_options=None): def iter_rules(self, hits_per_page=1000, request_options=None): page = 0 response = self.search_rules( - '', page=page, + '', page=page, hitsPerPage=hits_per_page, request_options=request_options ) @@ -712,7 +728,7 @@ def iter_rules(self, hits_per_page=1000, request_options=None): page += 1 response = self.search_rules( - '', page=page, + '', page=page, hitsPerPage=hits_per_page, request_options=request_options ) diff --git a/tests/test_index.py b/tests/test_index.py index 91e87e046..36f88d591 100644 --- a/tests/test_index.py +++ b/tests/test_index.py @@ -267,6 +267,27 @@ def test_batch_and_clear_rules(index): rules = index.search_rules() assert rules['nbHits'] == 0 +def test_move(index): + old_index_name = index.index_name + task = index.add_object({ "objectID": "Foo" }) + index.wait_task(task['taskID']) + + task = index.move('algolia-python-move') + index.wait_task(task['taskID']) + + res = index.client.list_indexes() + res_names = [elt['name'] for elt in res['items']] + + assert old_index_name not in res_names + assert index.index_name in res_names + + res = index.get_object("Foo") + assert res['objectID'] == "Foo" + + assert index.index_name == "algolia-python-move" + assert index._request_path == '/1/indexes/%s' % "algolia-python-move" + + index.client.delete_index('algolia-python-move') # Tear down def test_batch_and_clear_existing(index): rule = rule_stub() From 66404f1966938afd606f0030404cf5aed910d2a0 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 31 Oct 2018 11:30:50 +0100 Subject: [PATCH 2/5] Updates changelog --- CHANGELOG.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc1347764..516d42f46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,15 @@ +### [Unreleased] + +* Adds move method on index - PR [#386](https://github.com/algolia/algoliasearch-client-python/pull/386) + You can now move an index to a new destination directly on the index object. Usage: + ```python + index = client.init_index('name'); + index.move('new_name') + index.get_settings() # Get the settings of the `new_name` index + ``` ### 1.17.0 - 2018-06-19 @@ -13,11 +22,11 @@ Introduce new Analytics object, wrapper around the [Analytics API](https://www.algolia.com/doc/rest-api/analytics/) (more methods to come). -* 2 methods about taskID initially available in the `Index` moved to the `Client`. - You could get some taskID from the engine without necessarily have an instance of Index, +* 2 methods about taskID initially available in the `Index` moved to the `Client`. + You could get some taskID from the engine without necessarily have an instance of Index, instead of instantiating an index that you won't need, you can now call wait_task and get_task_status on the client. The original methods on the index still work and are **not** deprecated. - + ```python client.wait_ask(index_name, taskID) client.get_task_status(index_name, taskID) @@ -74,7 +83,7 @@ https://blog.algolia.com/travis-encrypted-variables-external-contributions/ Cursor can become so long that the generated URL fails (error HTTP 414). * Chore: Add Python version to the UserAgent - + ### 1.15.3 - 2018-03-15 * Remove the `[security]` flair of `requests` From c44a591a487352b58f617dcd538711fe0c1c09de Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 31 Oct 2018 11:31:50 +0100 Subject: [PATCH 3/5] Minor update on changelog --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 516d42f46..f4033955a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,6 @@ -### [Unreleased] - * Adds move method on index - PR [#386](https://github.com/algolia/algoliasearch-client-python/pull/386) You can now move an index to a new destination directly on the index object. Usage: ```python From e8140269dcd74a1c6f48aabd9a075f454df26b78 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 1 Nov 2018 10:15:07 +0100 Subject: [PATCH 4/5] Adds deprecated into move_index in client --- algoliasearch/client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/algoliasearch/client.py b/algoliasearch/client.py index fddafc3f5..abdbf28ac 100644 --- a/algoliasearch/client.py +++ b/algoliasearch/client.py @@ -316,6 +316,7 @@ def delete_index(self, index_name, request_options=None): def moveIndex(self, src_index_name, dst_index_name): return self.move_index(src_index_name, dst_index_name) + @deprecated def move_index(self, src_index_name, dst_index_name, request_options=None): """ Move an existing index. From 6a41ca280a6631b93df7ed10b9a46cb138ca736b Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 5 Nov 2018 11:14:46 +0100 Subject: [PATCH 5/5] Renames move to move_to --- CHANGELOG.md | 2 +- algoliasearch/index.py | 2 +- tests/test_index.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4033955a..e5aba812e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ You can now move an index to a new destination directly on the index object. Usage: ```python index = client.init_index('name'); - index.move('new_name') + index.move_to('new_name') index.get_settings() # Get the settings of the `new_name` index ``` diff --git a/algoliasearch/index.py b/algoliasearch/index.py index 02b7f5d90..fccde3be9 100644 --- a/algoliasearch/index.py +++ b/algoliasearch/index.py @@ -311,7 +311,7 @@ def delete_objects(self, objects, request_options=None): }) return self.batch(requests, request_options=request_options) - def move(self, new_index_name, request_options=None): + def move_to(self, new_index_name, request_options=None): """ Move the index. diff --git a/tests/test_index.py b/tests/test_index.py index 36f88d591..b64418640 100644 --- a/tests/test_index.py +++ b/tests/test_index.py @@ -267,12 +267,12 @@ def test_batch_and_clear_rules(index): rules = index.search_rules() assert rules['nbHits'] == 0 -def test_move(index): +def test_move_to(index): old_index_name = index.index_name task = index.add_object({ "objectID": "Foo" }) index.wait_task(task['taskID']) - task = index.move('algolia-python-move') + task = index.move_to('algolia-python-move') index.wait_task(task['taskID']) res = index.client.list_indexes()