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 = 1000, 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]
        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'
        index_name = algolia_index_name(options)
        tmp_options = options.merge({ :index_name => "#{index_name}.tmp" })
        tmp_settings = settings.dup
        tmp_index = algolia_ensure_init(tmp_options, tmp_settings, master_settings)
        algolia_find_in_batches(batch_size) do |group|
          if algolia_conditional_index?(tmp_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 = ::Algolia.move_index(tmp_index.name, index_name)
        tmp_index.wait_task(move_task["taskID"]) if synchronous == true
      end
      nil
    end
def algolia_reindex ( batch_size = 1000 , 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 ] 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' index_name = algolia_index_name ( options ) tmp_options = options . merge ( { :index_name => "#{index_name}.tmp" } ) tmp_settings = settings . dup tmp_index = algolia_ensure_init ( tmp_options , tmp_settings , master_settings ) algolia_find_in_batches ( batch_size ) do | group | if algolia_conditional_index? ( tmp_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 = :: Algolia . move_index ( tmp_index . name , index_name ) tmp_index . wait_task ( move_task [ "taskID" ] ) if synchronous == true 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 slaves of the temporary index # init temporary index # select only indexable objects
batch_size
<not_specific>
synchronous
<not_specific>