Created
July 17, 2012 18:36
-
-
Save terryjray/3131163 to your computer and use it in GitHub Desktop.
Postgres Full Text Search with hstore in Rails 3
This file contains hidden or 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
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 |
awesome! exactly what i needed
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
Thanks!