         # File lib/ferret/index.rb, line 83
     83:     def initialize(options = {}, &block)
     84:       super()
     85:
     86:       if options[:key]
     87:         @key = options[:key]
     88:         if @key.is_a?(Array)
     89:           @key.flatten.map {|k| k.to_s.intern}
     90:         end
     91:       end
     92:
     93:       if (fi = options[:field_infos]).is_a?(String)
     94:         options[:field_infos] = FieldInfos.load(fi)
     95:       end
     96:
     97:       @close_dir = options[:close_dir]
     98:       if options[:dir].is_a?(String)
     99:         options[:path] = options[:dir]
    100:       end
    101:       if options[:path]
    102:         @close_dir = true
    103:         begin
    104:           @dir = FSDirectory.new(options[:path], options[:create])
    105:         rescue IOError => io
    106:           @dir = FSDirectory.new(options[:path],
    107:                                  options[:create_if_missing] != false)
    108:         end
    109:       elsif options[:dir]
    110:         @dir = options[:dir]
    111:       else
    112:         options[:create] = true # this should always be true for a new RAMDir
    113:         @close_dir = true
    114:         @dir = RAMDirectory.new
    115:       end
    116:
    117:       options[:dir] = @dir
    118:       options[:lock_retry_time]||= 2
    119:       @dir.extend(MonitorMixin)
    120:       @dir.synchronize do
    121:         @options = options
    122:         if (!@dir.exists?("segments")) || options[:create]
    123:           IndexWriter.new(options).close
    124:         end
    125:         options[:analyzer]||= Ferret::Analysis::StandardAnalyzer.new
    126:
    127:         @searcher = nil
    128:         @writer = nil
    129:         @reader = nil
    130:
    131:         @options.delete(:create) # only create the first time if at all
    132:         @auto_flush = @options[:auto_flush] || false
    133:         if (@options[:id_field].nil? and
    134:             @key.is_a?(Symbol))
    135:           @id_field = @key
    136:         else
    137:           @id_field = @options[:id_field] || :id
    138:         end
    139:         @default_field = (@options[:default_field]||= :*)
    140:         @default_input_field = options[:default_input_field] || @id_field
    141:
    142:         if @default_input_field.respond_to?(:intern)
    143:           @default_input_field = @default_input_field.intern
    144:         end
    145:         @open = true
    146:         @qp = nil
    147:       end
    148:       if block
    149:         yield self
    150:         self.close
    151:       end
    152:     end