lib/algoliasearch-rails.rb
# reindex whole database using a extra temporary index + move operation
reindex whole database using a extra temporary index + move operation
reindex whole database using a extra temporary index + move operation
def algolia_reindex(batch_size = AlgoliaSearch::IndexSettings::DEFAULT_BATCH_SIZE, synchronous = false)
      return if algolia_without_auto_index_scope
      algolia_configurations.each do |options, settings|
        next if algolia_indexing_disabled?(options)
        next if options[:slave] || options[:replica]
        master_index = algolia_ensure_init(options, settings)
        master_settings = master_index.get_settings rescue {} 
        master_settings.merge!(JSON.parse(settings.to_settings.to_json)) 
        master_settings.delete :slaves
        master_settings.delete 'slaves'
        master_settings.delete :replicas
        master_settings.delete 'replicas'
        src_index_name = algolia_index_name(options)
        tmp_index_name = "#{src_index_name}.tmp"
        tmp_options = options.merge({ :index_name => tmp_index_name })
        tmp_options.delete(:per_environment) 
        tmp_settings = settings.dup
        if options[:check_settings] == false
          ::Algolia::copy_index!(src_index_name, tmp_index_name, %w(settings synonyms rules))
          tmp_index = SafeIndex.new(tmp_index_name, !!options[:raise_on_failure])
        else
          tmp_index = algolia_ensure_init(tmp_options, tmp_settings, master_settings)
        end
          algolia_find_in_batches(batch_size) do |group|
          if algolia_conditional_index?(options)
            group = group.select { |o| algolia_indexable?(o, tmp_options) }
          end
          objects = group.map { |o| tmp_settings.get_attributes(o).merge 'objectID' => algolia_object_id_of(o, tmp_options) }
          tmp_index.save_objects(objects)
        end
        move_task = SafeIndex.move_index(tmp_index.name, src_index_name)
        master_index.wait_task(move_task["taskID"]) if synchronous || options[:synchronous]
      end
      nil
    end
def algolia_reindex ( batch_size = AlgoliaSearch :: IndexSettings :: DEFAULT_BATCH_SIZE , synchronous = false ) return if algolia_without_auto_index_scope algolia_configurations . each do | options , settings | next if algolia_indexing_disabled? ( options ) next if options [ :slave ] || options [ :replica ] master_index = algolia_ensure_init ( options , settings ) master_settings = master_index . get_settings rescue { } master_settings . merge! ( JSON . parse ( settings . to_settings . to_json ) ) master_settings . delete :slaves master_settings . delete 'slaves' master_settings . delete :replicas master_settings . delete 'replicas' src_index_name = algolia_index_name ( options ) tmp_index_name = "#{src_index_name}.tmp" tmp_options = options . merge ( { :index_name => tmp_index_name } ) tmp_options . delete ( :per_environment ) tmp_settings = settings . dup if options [ :check_settings ] == false :: Algolia :: copy_index! ( src_index_name , tmp_index_name , %w( settings synonyms rules ) ) tmp_index = SafeIndex . new ( tmp_index_name , ! ! options [ :raise_on_failure ] ) else tmp_index = algolia_ensure_init ( tmp_options , tmp_settings , master_settings ) end algolia_find_in_batches ( batch_size ) do | group | if algolia_conditional_index? ( options ) group = group . select { | o | algolia_indexable? ( o , tmp_options ) } end objects = group . map { | o | tmp_settings . get_attributes ( o ) . merge 'objectID' => algolia_object_id_of ( o , tmp_options ) } tmp_index . save_objects ( objects ) end move_task = SafeIndex . move_index ( tmp_index . name , src_index_name ) master_index . wait_task ( move_task [ "taskID" ] ) if synchronous || options [ :synchronous ] end nil end
reindex whole database using a extra temporary index + move operation
reindex whole database using a extra temporary index + move operation
# fetch the master settings # if master doesn't exist yet # convert symbols to strings # remove the replicas of the temporary index # init temporary index # already included in the temporary index_name # select only indexable objects
batch_size
<not_specific>
synchronous
<not_specific>