Subject: Re: [sup-devel] [PATCH] xapian: translate from/to query term prefixes to search over both name and email fields

From: "Edward Z. Yang" <[email-masked]>
Date: Tue, 05 Jan 2010 16:06:10 -0500

At last! Good patch.

Cheers,
Edward
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: William Morgan <[email-masked]>
Date: Tue, 05 Jan 2010 13:01:30 -0800

Branch xapain-name-email, merged into next. Thanks!
-- 
William <[email-masked]>
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel

---

From: Rich Lane <[email-masked]>
Date: Fri, 1 Jan 2010 20:37:26 -0800

---
 lib/sup/xapian_index.rb |   19 ++++++++++++-------
 1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/lib/sup/xapian_index.rb b/lib/sup/xapian_index.rb
index cebb148..c192b26 100644
--- a/lib/sup/xapian_index.rb
+++ b/lib/sup/xapian_index.rb
@@ -159,14 +159,15 @@ EOS
 
     subs = HookManager.run("custom-search", :subs => s) || s
     subs = subs.gsub(/\b(to|from):(\S+)\b/) do
-      field, name = $1, $2
-      if(p = ContactManager.contact_for(name))
-        [field, p.email]
-      elsif name == "me"
-        [field, "(" + AccountManager.user_emails.join("||") + ")"]
+      field, value = $1, $2
+      email_field, name_field = %w(email name).map { |x| "#{field}_#{x}" }
+      if(p = ContactManager.contact_for(value))
+        "#{email_field}:#{p.email}"
+      elsif value == "me"
+        '(' + AccountManager.user_emails.map { |e| "#{email_field}:#{e}" }.join(' OR ') + ')'
       else
-        [field, name]
-      end.join(":")
+        "(#{email_field}:#{value} OR #{name_field}:#{value})"
+      end
     end
 
     ## if we see a label:deleted or a label:spam term anywhere in the query
@@ -250,6 +251,8 @@ EOS
       end
     end
 
+    debug "translated query: #{subs.inspect}"
+
     qp = Xapian::QueryParser.new
     qp.database = @xapian
     qp.stemmer = Xapian::Stem.new(STEM_LANGUAGE)
@@ -260,6 +263,8 @@ EOS
     BOOLEAN_PREFIX.each { |k,v| qp.add_boolean_prefix k, v }
     xapian_query = qp.parse_query(subs, Xapian::QueryParser::FLAG_PHRASE|Xapian::QueryParser::FLAG_BOOLEAN|Xapian::QueryParser::FLAG_LOVEHATE|Xapian::QueryParser::FLAG_WILDCARD, PREFIX['body'])
 
+    debug "parsed xapian query: #{xapian_query.description}"
+
     raise ParseError if xapian_query.nil? or xapian_query.empty?
     query[:qobj] = xapian_query
     query[:text] = s
-- 
1.6.3.3