Skip to content

Instantly share code, notes, and snippets.

@ngauthier
Created April 5, 2010 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngauthier/356857 to your computer and use it in GitHub Desktop.
Save ngauthier/356857 to your computer and use it in GitHub Desktop.
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