1 ## Index interface, subclassed by Ferret indexer.
9 debug "optional 'chronic' library not found; date-time query restrictions disabled"
16 include InteractiveLock
18 class LockError < StandardError
23 def method_missing m; @h[m.to_s] end
28 def initialize dir=BASE_DIR
30 @lock = Lockfile.new lockfile, :retries => 0, :max_age => nil
33 def lockfile; File.join @dir, "lock" end
36 debug "locking #{lockfile}..."
39 rescue Lockfile::MaxTriesLockError
40 raise LockError, @lock.lockinfo_on_disk
44 def start_lock_update_thread
45 @lock_update_thread = Redwood::reporting_thread("lock update") do
53 def stop_lock_update_thread
54 @lock_update_thread.kill if @lock_update_thread
55 @lock_update_thread = nil
59 if @lock && @lock.locked?
60 debug "unlocking #{lockfile}..."
66 SourceManager.load_sources
71 debug "saving index and sources..."
72 FileUtils.mkdir_p @dir unless File.exists? @dir
73 SourceManager.save_sources
81 def add_message m; unimplemented end
82 def update_message m; unimplemented end
83 def update_message_state m; unimplemented end
93 def contains? m; contains_id? m.id end
99 def empty?; size == 0 end
101 ## Yields a message-id and message-building lambda for each
102 ## message that matches the given query, in descending date order.
103 ## You should probably not call this on a block that doesn't break
104 ## rather quickly because the results can be very large.
105 def each_id_by_date query={}
109 ## Return the number of matches for query in the index
110 def num_results_for query={}
114 ## yield all messages in the thread containing 'm' by repeatedly
115 ## querying the index. yields pairs of message ids and
116 ## message-building lambdas, so that building an unwanted message
117 ## can be skipped in the block if desired.
119 ## only two options, :limit and :skip_killed. if :skip_killed is
120 ## true, stops loading any thread if a message with a :killed flag
122 def each_message_in_thread_for m, opts={}
126 ## Load message with the given message-id from the index
131 ## Delete message with the given message-id from the index
136 ## Given an array of email addresses, return an array of Person objects that
137 ## have sent mail to or received mail from any of the given addresses.
138 def load_contacts email_addresses, h={}
142 ## Yield each message-id matching query
147 ## Yield each message matching query
148 def each_message query={}, &b
149 each_id query do |id|
150 yield build_message(id)
154 ## Implementation-specific optimization step
159 ## Return the id source of the source the message with the given message-id
165 class ParseError < StandardError; end
167 ## parse a query string from the user. returns a query object
168 ## that can be passed to any index method with a 'query'
171 ## raises a ParseError if something went wrong.
177 index_name = ENV['SUP_INDEX'] || $config[:index] || DEFAULT_INDEX
179 when "xapian"; require "sup/xapian_index"
180 when "ferret"; require "sup/ferret_index"
181 else fail "unknown index type #{index_name.inspect}"
183 Index = Redwood.const_get "#{index_name.capitalize}Index"
184 debug "using index #{Index.name}"