From: Rich Lane <rlane@club.cc.cmu.edu>
To: sup-devel@rubyforge.org
Subject: [sup-devel] [PATCH] xapian: translate from/to query term prefixes to search over both name and email fields
Date: Fri, 1 Jan 2010 20:37:26 -0800 [thread overview]
Message-ID: <1262407046-2029-1-git-send-email-rlane@club.cc.cmu.edu> (raw)
---
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
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
next reply other threads:[~2010-01-02 4:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-02 4:37 Rich Lane [this message]
2010-01-05 21:01 ` William Morgan
2010-01-05 21:06 ` Edward Z. Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1262407046-2029-1-git-send-email-rlane@club.cc.cmu.edu \
--to=rlane@club.cc.cmu.edu \
--cc=sup-devel@rubyforge.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox