From: William Morgan Date: Wed, 26 Dec 2007 20:44:37 +0000 (-0800) Subject: make explicitly searching for "label:spam" and "label:deleted" work X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=b2d78427be803808497aca1a8fcf868e3c778e0e;p=sup make explicitly searching for "label:spam" and "label:deleted" work see comments for how this is possible without implementing our own full-blown Ferret query parser. --- diff --git a/lib/sup/index.rb b/lib/sup/index.rb index c21375d..84771ca 100644 --- a/lib/sup/index.rb +++ b/lib/sup/index.rb @@ -383,7 +383,7 @@ EOS end def has_any_from_source_with_label? source, label - q = Ferret::Search::BooleanQuery.new + q = erret::Search::BooleanQuery.new q.add_query Ferret::Search::TermQuery.new("source_id", source.id.to_s), :must q.add_query Ferret::Search::TermQuery.new("label", label.to_s), :must index.search(q, :limit => 1).total_hits > 0 @@ -417,8 +417,24 @@ protected [field, name] end.join(":") end - - # gmail style "is" operator + + ## if we see a label:deleted or a label:spam term anywhere in the query + ## string, we set the extra load_spam or load_deleted options to true. + ## bizarre? well, because the query allows arbitrary parenthesized boolean + ## expressions, without fully parsing the query, we can't tell whether + ## the user is explicitly directing us to search spam messages or not. + ## e.g. if the string is -(-(-(-(-label:spam)))), does the user want to + ## search spam messages or not? + ## + ## so, we rely on the fact that turning these extra options ON turns OFF + ## the adding of "-label:deleted" or "-label:spam" terms at the very + ## final stage of query processing. if the user wants to search spam + ## messages, not adding that is the right thing; if he doesn't want to + ## search spam messages, then not adding it won't have any effect. + extraopts[:load_spam] = true if subs =~ /\blabel:spam\b/ + extraopts[:load_deleted] = true if subs =~ /\blabel:deleted\b/ + + ## gmail style "is" operator subs = subs.gsub(/\b(is):(\S+)\b/) do field, label = $1, $2 case label