Skip to content

Instantly share code, notes, and snippets.

@terryjray
Created July 17, 2012 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save terryjray/3131163 to your computer and use it in GitHub Desktop.
Save terryjray/3131163 to your computer and use it in GitHub Desktop.
Postgres Full Text Search with hstore in Rails 3
class Product < ActiveRecord::Base
# our hstore column, make sure gem 'activerecord-postgres-hstore' is in your Gemfile
# and you've run: rails g hstore:setup
serialize :data, ActiveRecord::Coders::Hstore
# name is a string col
attr_accessible :data, :name
def self.search(query)
where("name @@ :q or CAST(avals(data) AS text) @@ :q", q: query)
end
end
@dallasread
Copy link

Thanks!

@caherrerapa
Copy link

awesome! exactly what i needed

@joellusky
Copy link

Thanks this is great! Can you explain what _@@_ does?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment