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