def load_contacts emails, h={}
q = Ferret::Search::BooleanQuery.new true
emails.each do |e|
qq = Ferret::Search::BooleanQuery.new true
qq.add_query Ferret::Search::TermQuery.new(:from, e), :should
qq.add_query Ferret::Search::TermQuery.new(:to, e), :should
q.add_query qq
end
q.add_query Ferret::Search::TermQuery.new(:label, "spam"), :must_not
debug "contact search: #{q}"
contacts = {}
num = h[:num] || 20
@index_mutex.synchronize do
@index.search_each q, :sort => "date DESC", :limit => :all do |docid, score|
break if contacts.size >= num
f = @index[docid][:from]
t = @index[docid][:to]
if AccountManager.is_account_email? f
t.split(" ").each { |e| contacts[Person.from_address(e)] = true }
else
contacts[Person.from_address(f)] = true
end
end
end
contacts.keys.compact
end