]> git.cworth.org Git - sup/commitdiff
expand contact aliases in to: and from: fields for searches
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Wed, 25 Jul 2007 00:32:31 +0000 (00:32 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Wed, 25 Jul 2007 00:32:31 +0000 (00:32 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@507 5c8cc53c-5e98-4d25-b20a-d8db53a31250

lib/sup/index.rb

index 731946890d5693e643b5d62e0efc5b47279a5eba..16528a4ba9348ed0e3bcf2b1f25727ed6ccc56be 100644 (file)
@@ -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]