Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Aug 19, 2013

Thanks!

@caherrerapa

This comment has been minimized.

Copy link

commented Dec 20, 2014

awesome! exactly what i needed

@joellusky

This comment has been minimized.

Copy link

commented Aug 14, 2015

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
You can’t perform that action at this time.