def add_indexes(indexes)
      @dir.synchronize do
        ensure_writer_open()
        indexes = [indexes].flatten   # make sure we have an array
        return if indexes.size == 0 # nothing to do
        if indexes[0].is_a?(Index)
          indexes.delete(self) # don't merge with self
          indexes = indexes.map {|index| index.reader }
        elsif indexes[0].is_a?(Ferret::Store::Directory)
          indexes.delete(@dir) # don't merge with self
          indexes = indexes.map {|dir| IndexReader.new(dir) }
        elsif indexes[0].is_a?(IndexReader)
          indexes.delete(@reader) # don't merge with self
        else
          raise ArgumentError, "Unknown index type when trying to merge indexes"
        end
        ensure_writer_open
        @writer.add_readers(indexes)
      end
    end
def add_indexes(indexes)
      @dir.synchronize do
        ensure_writer_open()
        indexes = [indexes].flatten   # make sure we have an array
        return if indexes.size == 0 # nothing to do
        if indexes[0].is_a?(Index)
          indexes.delete(self) # don't merge with self
          indexes = indexes.map {|index| index.reader }
        elsif indexes[0].is_a?(Ferret::Store::Directory)
          indexes.delete(@dir) # don't merge with self
          indexes = indexes.map {|dir| IndexReader.new(dir) }
        elsif indexes[0].is_a?(IndexReader)
          indexes.delete(@reader) # don't merge with self
        else
          raise ArgumentError, "Unknown index type when trying to merge indexes"
        end
        ensure_writer_open
        @writer.add_readers(indexes)
      end
    end
Merges all segments from an index or an array of indexes into this
 index. You can pass a single Index::Index, Index::Reader,
 Store::Directory or an array of any single one of these.

 This may be used to parallelize batch indexing. A large document
 collection can be broken into sub-collections. Each sub-collection can
 be indexed in parallel, on a different thread, process or machine and
 perhaps all in memory. The complete index can then be created by
 merging sub-collection indexes with this method.

 After this completes, the index is optimized.