def rebuild_index(options={}, finder_options={})
      logger.info "=== Rebuilding index for: #{self.index_type}" unless options[:silent]

      if options[:drop]
        logger.info "Dropping index for: #{self.index_type}" unless options[:silent]
        index_adapter.drop_index(self)
      end

      finder_options[:batch_size] ||= 100
      finder_options[:view] ||= :all
      finder_options[:bypass_index] = true

      options[:batch_size] ||= 100
      options[:commit] = true unless options.has_key?(:commit)
      options[:optimize] = true unless options.has_key?(:optimize)

      logger.info "Offset: #{finder_options[:offset]}" unless options[:silent]
      logger.info "Stop row: #{finder_options[:stop_row]}" unless options[:silent]

      buffer = []
      items_processed = 0
      loop = 0

      # Depending on whether the model has a scan or find method, use that.
      # scan is from Bigrecord models, and find is from Activerecord.
      if self.respond_to?(:scan)
        self.scan(finder_options) do |r|
          items_processed += 1
          buffer << r
          if buffer.size > options[:batch_size]
            loop += 1
            index_adapter.process_index_batch(buffer, loop, options)
            buffer.clear
          end
        end

        index_adapter.process_index_batch(buffer, loop, options) unless buffer.empty?
      elsif self.respond_to?(:find)
        ar_options = {:limit => finder_options[:batch_size]}

        while
          loop += 1

          buffer = self.find_without_index(:all, ar_options)
          break if buffer.empty?
          items_processed += buffer.size

          index_adapter.process_index_batch(buffer, loop, options)

          break if buffer.size < finder_options[:batch_size]

          buffer.clear
          ar_options[:offset] = (loop * finder_options[:batch_size])+1
        end
      else
        raise "Your model needs at least a scan() or find() method"
      end

      if items_processed > 0
        logger.info "Index for #{self.index_type} has been rebuilt (#{items_processed} records)." unless options[:silent]
      else
        logger.info "Nothing to index for #{self.index_type}." unless options[:silent]
      end

      logger.info "=== Finished rebuilding index for: #{self.index_type}" unless options[:silent]

      return items_processed
    end
def rebuild_index(options={}, finder_options={})
      logger.info "=== Rebuilding index for: #{self.index_type}" unless options[:silent]

      if options[:drop]
        logger.info "Dropping index for: #{self.index_type}" unless options[:silent]
        index_adapter.drop_index(self)
      end

      finder_options[:batch_size] ||= 100
      finder_options[:view] ||= :all
      finder_options[:bypass_index] = true

      options[:batch_size] ||= 100
      options[:commit] = true unless options.has_key?(:commit)
      options[:optimize] = true unless options.has_key?(:optimize)

      logger.info "Offset: #{finder_options[:offset]}" unless options[:silent]
      logger.info "Stop row: #{finder_options[:stop_row]}" unless options[:silent]

      buffer = []
      items_processed = 0
      loop = 0

      # Depending on whether the model has a scan or find method, use that.
      # scan is from Bigrecord models, and find is from Activerecord.
      if self.respond_to?(:scan)
        self.scan(finder_options) do |r|
          items_processed += 1
          buffer << r
          if buffer.size > options[:batch_size]
            loop += 1
            index_adapter.process_index_batch(buffer, loop, options)
            buffer.clear
          end
        end

        index_adapter.process_index_batch(buffer, loop, options) unless buffer.empty?
      elsif self.respond_to?(:find)
        ar_options = {:limit => finder_options[:batch_size]}

        while
          loop += 1

          buffer = self.find_without_index(:all, ar_options)
          break if buffer.empty?
          items_processed += buffer.size

          index_adapter.process_index_batch(buffer, loop, options)

          break if buffer.size < finder_options[:batch_size]

          buffer.clear
          ar_options[:offset] = (loop * finder_options[:batch_size])+1
        end
      else
        raise "Your model needs at least a scan() or find() method"
      end

      if items_processed > 0
        logger.info "Index for #{self.index_type} has been rebuilt (#{items_processed} records)." unless options[:silent]
      else
        logger.info "Nothing to index for #{self.index_type}." unless options[:silent]
      end

      logger.info "=== Finished rebuilding index for: #{self.index_type}" unless options[:silent]

      return items_processed
    end
Dispatches a command to the current adapter to rebuild the index.

 @return <Integer> representing number of items processed.