Class: Algolia::AccountClient
- Inherits:
-
Object
- Object
- Algolia::AccountClient
- Defined in:
- lib/algolia/account_client.rb
Overview
A class which encapsulates the HTTPS communication with the Algolia API server for cross-app operations.
Class Method Summary collapse
-
.copy_index(source_index, destination_index, request_options = {}) ⇒ Object
Copies settings, synonyms, rules and objects from the source index to the destination index.
-
.copy_index!(source_index, destination_index, request_options = {}) ⇒ Object
The method copy settings, synonyms, rules and objects from the source index to the destination index and wait end of indexing.
Class Method Details
.copy_index(source_index, destination_index, request_options = {}) ⇒ 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
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/algolia/account_client.rb', line 21 def copy_index(source_index, destination_index, = {}) raise AlgoliaError.new('The indexes are in the same application. Use Algolia::Client.copy_index instead.') if source_index.client.application_id == destination_index.client.application_id begin settings = destination_index.get_settings() rescue AlgoliaError # Destination index does not exists. We can proceed. else raise AlgoliaError.new("Destination index already exists. Please delete it before copying index across applications.") end responses = [] settings = source_index.get_settings() responses << destination_index.set_settings(settings, {}, ) synonyms = [] source_index.export_synonyms(100, ) do |synonym| synonym.delete('_highlightResult') synonyms << synonym end responses << destination_index.batch_synonyms(synonyms, false, false, ) rules = [] source_index.export_rules(100, ) do |rule| rule.delete('_highlightResult') rules << rule end responses << destination_index.batch_rules(rules, false, false, ) # Copy objects responses = [] batch = [] batch_size = 1000 count = 0 source_index.browse do |obj| batch << obj count += 1 if count == batch_size responses << destination_index.save_objects(batch, ) batch = [] count = 0 end end if batch.any? responses << destination_index.save_objects(batch, ) end responses end |
.copy_index!(source_index, destination_index, request_options = {}) ⇒ Object
The method copy settings, synonyms, rules and objects from the source index to the destination index and wait end of indexing. 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
88 89 90 91 92 93 94 95 96 |
# File 'lib/algolia/account_client.rb', line 88 def copy_index!(source_index, destination_index, = {}) responses = self.copy_index(source_index, destination_index, ) responses.each do |res| destination_index.wait_task(res['taskID'], WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY, ) end responses end |