Class: Algolia::Account::Client
- Inherits:
-
Object
- Object
- Algolia::Account::Client
- Defined in:
- lib/algolia/account_client.rb
Class Method Summary collapse
-
.copy_index(src_index, dest_index, opts = {}) ⇒ Object
Copies settings, synonyms, rules and objects from the source index to the destination index.
-
.copy_index!(src_index, dest_index, opts = {}) ⇒ Object
Copies settings, synonyms, rules and objects from the source index to the destination index ans wait for the task to complete.
Class Method Details
.copy_index(src_index, dest_index, opts = {}) ⇒ Object
Copies settings, synonyms, rules and objects from the source index to the destination index. The replicas of the source index should not be copied.
Throw an exception if the destination index already exists Throw an exception if the indices are on the same application
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/algolia/account_client.rb', line 15 def copy_index(src_index, dest_index, opts = {}) raise AlgoliaError, 'The indices are on the same application. Use Algolia::Search::Client.copy_index instead.' if src_index.config.app_id == dest_index.config.app_id begin dest_settings = dest_index.get_settings raise AlgoliaError, 'Destination index already exists. Please delete it before copying index across applications.' if dest_settings rescue AlgoliaHttpError => e raise e if e.code != 404 end responses = MultipleResponse.new # Copy settings settings = src_index.get_settings responses.push(dest_index.set_settings(settings, opts)) # Copy synonyms synonyms = src_index.browse_synonyms responses.push(dest_index.save_synonyms(synonyms, opts)) # Copy rules rules = src_index.browse_rules responses.push(dest_index.save_rules(rules, opts)) # Copy objects objects = src_index.browse_objects responses.push(dest_index.save_objects(objects, opts)) responses end |
.copy_index!(src_index, dest_index, opts = {}) ⇒ Object
Copies settings, synonyms, rules and objects from the source index to the destination index ans wait for the task to complete. The replicas of the source index should not be copied.
Throw an exception if the destination index already exists Throw an exception if the indices are on the same application
58 59 60 61 |
# File 'lib/algolia/account_client.rb', line 58 def copy_index!(src_index, dest_index, opts = {}) response = copy_index(src_index, dest_index, opts) response.wait(opts) end |