From 9b93ad36260cb6fe905c180a13fb15c4139cb146 Mon Sep 17 00:00:00 2001 From: wmorgan Date: Mon, 29 Oct 2007 15:41:39 +0000 Subject: [PATCH] rename :load_killed to :skip_killed and switched logic so that killed threads are loaded by default (only inbox mode wants to ignore them) git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@646 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- lib/sup/index.rb | 12 ++++++------ lib/sup/modes/inbox-mode.rb | 2 +- lib/sup/modes/label-search-results-mode.rb | 1 - lib/sup/modes/search-results-mode.rb | 2 +- lib/sup/thread.rb | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/sup/index.rb b/lib/sup/index.rb index 82fa173..7dff1cd 100644 --- a/lib/sup/index.rb +++ b/lib/sup/index.rb @@ -225,7 +225,9 @@ EOS ## 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}" @@ -261,15 +263,13 @@ EOS q.add_query Ferret::Search::TermQuery.new(:message_id, id), :should q.add_query Ferret::Search::TermQuery.new(:refs, id), :should - ## load_killed is true so that we can abort if any message in - ## the thread has the killed label. - 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] - if @index[docid][:label].split(/\s+/).include?("killed") && !opts[:load_killed] + if @index[docid][:label].split(/\s+/).include?("killed") && opts[:skip_killed] killed = true break end @@ -400,7 +400,7 @@ protected 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 diff --git a/lib/sup/modes/inbox-mode.rb b/lib/sup/modes/inbox-mode.rb index 23da979..aa40318 100644 --- a/lib/sup/modes/inbox-mode.rb +++ b/lib/sup/modes/inbox-mode.rb @@ -9,7 +9,7 @@ class InboxMode < ThreadIndexMode end def initialize - super [:inbox, :sent], { :label => :inbox } + super [:inbox, :sent], { :label => :inbox, :skip_killed => true } raise "can't have more than one!" if defined? @@instance @@instance = self end diff --git a/lib/sup/modes/label-search-results-mode.rb b/lib/sup/modes/label-search-results-mode.rb index 836ee66..9fc051f 100644 --- a/lib/sup/modes/label-search-results-mode.rb +++ b/lib/sup/modes/label-search-results-mode.rb @@ -4,7 +4,6 @@ class LabelSearchResultsMode < ThreadIndexMode def initialize labels @labels = labels opts = { :labels => @labels } - opts[:load_killed] = true if labels.include? :killed opts[:load_deleted] = true if labels.include? :deleted opts[:load_spam] = true if labels.include? :spam super [], opts diff --git a/lib/sup/modes/search-results-mode.rb b/lib/sup/modes/search-results-mode.rb index 1b0d456..73e9809 100644 --- a/lib/sup/modes/search-results-mode.rb +++ b/lib/sup/modes/search-results-mode.rb @@ -3,7 +3,7 @@ module Redwood class SearchResultsMode < ThreadIndexMode def initialize qobj @qobj = qobj - super [], { :qobj => @qobj, :load_killed => true, :load_spam => false } + super [], { :qobj => @qobj } end ## a proper is_relevant? method requires some way of asking ferret diff --git a/lib/sup/thread.rb b/lib/sup/thread.rb index b154ac0..722ba34 100644 --- a/lib/sup/thread.rb +++ b/lib/sup/thread.rb @@ -306,7 +306,7 @@ class ThreadSet next if contains_id? mid m = builder.call - load_thread_for_message m, :load_killed => opts[:load_killed], :load_deleted => opts[:load_deleted], :load_spam => opts[:load_spam] + load_thread_for_message m, :skip_killed => opts[:skip_killed], :load_deleted => opts[:load_deleted], :load_spam => opts[:load_spam] yield size if block_given? end end -- 2.45.2