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