include Singleton
attr_reader :index
+ alias ferret index
def initialize dir=BASE_DIR
@dir = dir
@sources = {}
docid, entry = load_entry_for_id m.id unless docid && entry
raise "no source info for message #{m.id}" unless m.source && m.source_info
- raise "trying deleting non-corresponding entry #{docid}" if docid && @index[docid][:message_id] != m.id
+ raise "trying to delete non-corresponding entry #{docid} with index message-id #{@index[docid][:message_id].inspect} and parameter message id #{m.id.inspect}" if docid && @index[docid][:message_id] != m.id
source_id =
if m.source.is_a? Integer
- raise "Debugging: integer source set"
m.source
else
m.source.id or raise "unregistered source #{m.source} (id #{m.source.id.inspect})"
docid, entry = load_entry_for_id m.id
## this hasn't been triggered in a long time. TODO: decide whether it's still a problem.
- raise "just added message #{m.id} but couldn't find it in a search" unless docid
+ raise "just added message #{m.id.inspect} but couldn't find it in a search" unless docid
true
end
## message-building lambdas, so that building an unwanted message
## can be skipped in the block if desired.
##
- ## stops loading any thread if a message with a :killed flag is found.
+ ## only two options, :limit and :skip_killed. if :skip_killed is
+ ## true, stops loading any thread if a message with a :killed flag
+ ## is found.
SAME_SUBJECT_DATE_LIMIT = 7
def each_message_in_thread_for m, opts={}
- Redwood::log "Building thread for #{m.id}: #{m.subj}"
+ #Redwood::log "Building thread for #{m.id}: #{m.subj}"
messages = {}
searched = {}
num_queries = 0
q.add_query Ferret::Search::TermQuery.new(:message_id, id), :should
q.add_query Ferret::Search::TermQuery.new(:refs, id), :should
- q = build_query :qobj => q, :load_killed => true
+ q = build_query :qobj => q
num_queries += 1
+ killed = false
@index.search_each(q, :limit => :all) do |docid, score|
break if opts[:limit] && messages.size >= opts[:limit]
- break if @index[docid][:label].split(/\s+/).include? "killed" unless opts[:load_killed]
+ if @index[docid][:label].split(/\s+/).include?("killed") && opts[:skip_killed]
+ killed = true
+ break
+ end
mid = @index[docid][:message_id]
unless messages.member?(mid)
- Redwood::log "got #{mid} as a child of #{id}"
+ #Redwood::log "got #{mid} as a child of #{id}"
messages[mid] ||= lambda { build_message docid }
refs = @index[docid][:refs].split(" ")
pending += refs
end
end
end
- Redwood::log "ran #{num_queries} queries to build thread of #{messages.size + 1} messages for #{m.id}" if num_queries > 0
- messages.each { |mid, builder| yield mid, builder }
+ if killed
+ Redwood::log "thread for #{m.id} is killed, ignoring"
+ false
+ else
+ Redwood::log "ran #{num_queries} queries to build thread of #{messages.size + 1} messages for #{m.id}: #{m.subj}" if num_queries > 0
+ messages.each { |mid, builder| yield mid, builder }
+ true
+ end
end
## builds a message object from a ferret result
"from" => doc[:from],
"to" => doc[:to],
"message-id" => doc[:message_id],
- "references" => doc[:refs],
+ "references" => doc[:refs].split(/\s+/).map { |x| "<#{x}>" }.join(" "),
}
Message.new :source => source, :source_info => doc[:source_info].to_i,
num = h[:num] || 20
@index.search_each(q, :sort => "date DESC", :limit => :all) do |docid, score|
break if contacts.size >= num
- #Redwood::log "got message with to: #{@index[docid][:to].inspect} and from: #{@index[docid][:from].inspect}"
+ #Redwood::log "got message #{docid} to: #{@index[docid][:to].inspect} and from: #{@index[docid][:from].inspect}"
f = @index[docid][:from]
t = @index[docid][:to]
def parse_user_query_string str
str2 = str.gsub(/(to|from):(\S+)/) do
field, name = $1, $2
- if(p = ContactManager.person_with(name))
+ if(p = ContactManager.contact_for(name))
[field, p.email]
else
[field, name]
query.add_query Ferret::Search::TermQuery.new("label", "spam"), :must_not unless opts[:load_spam] || labels.include?(:spam)
query.add_query Ferret::Search::TermQuery.new("label", "deleted"), :must_not unless opts[:load_deleted] || labels.include?(:deleted)
- query.add_query Ferret::Search::TermQuery.new("label", "killed"), :must_not unless opts[:load_killed] || labels.include?(:killed)
+ query.add_query Ferret::Search::TermQuery.new("label", "killed"), :must_not if opts[:skip_killed]
query
end