Skip to content

Commit 81b61a2

Browse files
Merge pull request #322 from algolia/feat/scoped_copy
Feat/scoped copy
2 parents b638b39 + 2a26094 commit 81b61a2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

algoliasearch/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,16 +303,22 @@ def move_index(self, src_index_name, dst_index_name, request_options=None):
303303
def copyIndex(self, src_index_name, dst_index_name):
304304
return self.copy_index(src_index_name, dst_index_name)
305305

306-
def copy_index(self, src_index_name, dst_index_name, request_options=None):
306+
def copy_index(self, src_index_name, dst_index_name, request_options=None, scope=None):
307307
"""
308308
Copy an existing index.
309309
310310
@param src_index_name the name of index to copy.
311311
@param dst_index_name the new index name that will contains a copy of
312312
src_index_name (destination will be overriten if it already exist).
313+
@param scope the scope of the copy, as a list. Possible items are:
314+
settings, rules, synonyms.
313315
"""
314316
path = '/1/indexes/%s/operation' % safe(src_index_name)
315317
request = {'operation': 'copy', 'destination': dst_index_name}
318+
319+
if scope is not None:
320+
request['scope'] = scope
321+
316322
return self._req(False, path, 'POST', request_options, data=request)
317323

318324
@deprecated

tests/test_client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,29 @@ def test_copy(double_indexes):
181181
assert res[0]['hits'] == res[1]['hits']
182182

183183

184+
def test_scoped_copy(double_indexes):
185+
index1 = double_indexes[0]
186+
index2 = double_indexes[1]
187+
188+
task = index1.set_settings({'searchableAttributes': ['name']})
189+
index1.wait_task(task['taskID'])
190+
191+
task = index1.client.copy_index(
192+
index1.index_name, index2.index_name, scope=['settings']
193+
)
194+
index1.wait_task(task['taskID'])
195+
196+
# Check that the settings are the same.
197+
settings1 = index1.get_settings()
198+
settings2 = index2.get_settings()
199+
assert settings1 == settings2
200+
201+
# Check that the objects are still different
202+
res1 = index1.search('')
203+
res2 = index2.search('')
204+
assert res1 != res2
205+
206+
184207
def test_move(double_indexes):
185208
index1 = double_indexes[0]
186209
index2 = double_indexes[1]

0 commit comments

Comments
 (0)