From 01609d744a2dceb52915c57c5bbf4fca5a410970 Mon Sep 17 00:00:00 2001 From: wmorgan Date: Wed, 25 Jul 2007 00:32:31 +0000 Subject: [PATCH] expand contact aliases in to: and from: fields for searches git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@507 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- lib/sup/index.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/sup/index.rb b/lib/sup/index.rb index 7319468..16528a4 100644 --- a/lib/sup/index.rb +++ b/lib/sup/index.rb @@ -359,7 +359,20 @@ EOS protected - def parse_user_query_string str; @qparser.parse str; end + def parse_user_query_string str + str2 = str.gsub(/(to|from):(\S+)/) do + field, name = $1, $2 + if(p = ContactManager.person_with(name)) + [field, p.email] + else + [field, name] + end.join(":") + end + + Redwood::log "translated #{str} to #{str2}" unless str2 == str + @qparser.parse str2 + end + def build_query opts query = Ferret::Search::BooleanQuery.new query.add_query opts[:qobj], :must if opts[:qobj] -- 2.45.2