* [sup-devel] [PATCH] xapian: translate from/to query term prefixes to search over both name and email fields
@ 2010-01-02 4:37 Rich Lane
2010-01-05 21:01 ` William Morgan
2010-01-05 21:06 ` Edward Z. Yang
0 siblings, 2 replies; 3+ messages in thread
From: Rich Lane @ 2010-01-02 4:37 UTC (permalink / raw)
To: sup-devel
---
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [sup-devel] [PATCH] xapian: translate from/to query term prefixes to search over both name and email fields
2010-01-02 4:37 [sup-devel] [PATCH] xapian: translate from/to query term prefixes to search over both name and email fields Rich Lane
@ 2010-01-05 21:01 ` William Morgan
2010-01-05 21:06 ` Edward Z. Yang
1 sibling, 0 replies; 3+ messages in thread
From: William Morgan @ 2010-01-05 21:01 UTC (permalink / raw)
To: sup-devel
Branch xapain-name-email, merged into next. Thanks!
--
William <wmorgan-sup@masanjin.net>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [sup-devel] [PATCH] xapian: translate from/to query term prefixes to search over both name and email fields
2010-01-02 4:37 [sup-devel] [PATCH] xapian: translate from/to query term prefixes to search over both name and email fields Rich Lane
2010-01-05 21:01 ` William Morgan
@ 2010-01-05 21:06 ` Edward Z. Yang
1 sibling, 0 replies; 3+ messages in thread
From: Edward Z. Yang @ 2010-01-05 21:06 UTC (permalink / raw)
To: Rich Lane; +Cc: sup-devel
At last! Good patch.
Cheers,
Edward
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-01-05 21:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-02 4:37 [sup-devel] [PATCH] xapian: translate from/to query term prefixes to search over both name and email fields Rich Lane
2010-01-05 21:01 ` William Morgan
2010-01-05 21:06 ` Edward Z. Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox