Created
April 5, 2010 20:43
-
-
Save ngauthier/356857 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Search | |
VECTORS = [ | |
{:klass => Company, :columns => ['ticker', 'name']}, | |
{:klass => Executive, :columns => ['name']} | |
] | |
class << self | |
def find(query) | |
query = query.split(' ').join(' & ') | |
return Search::VECTORS.collect{|tuple| | |
Array(tuple[:columns]).collect{|column| | |
tuple[:klass].find(:all, | |
:conditions => [ | |
%Q[to_tsvector('english', #{column}) @@ to_tsquery(?)], query | |
] | |
) | |
} | |
}.flatten.uniq | |
end | |
end | |
end | |
def Search(query) | |
return Search.find(query) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment