Rails: How do I search tags generated by Act_As_Taggable_On with PG_Search? (postgresql) Rails: How do I search tags generated by Act_As_Taggable_On with PG_Search? (postgresql) postgresql postgresql

Rails: How do I search tags generated by Act_As_Taggable_On with PG_Search? (postgresql)


A much more simple approach is just using the association and search that through pg_search which is done like this:

class Item < ActiveRecord::Base include PgSearch    pg_search_scope :full_search,     :against => {      :item_status => 'A',    :title => 'B',    :description => 'C'       },           :associated_against => {    :tags => [:name]       }end 

I just implemented this in one of my projects and it worked well (searched through tag names). Unfortunately I can't figure out how to weight an associated relationship since it says "tags" column not found in Items table.


This worked for me to get the tags weighted as well

    pg_search_scope :search_by_weight,       :against => {        :title => 'B',      :content => 'C'        },           :associated_against => {      :tags => { :name => 'A' }        },    using: {tsearch: {dictionary: "english"}}


I wrote my implementation in plpgsql a few years ago. See my blog: http://omarqureshi.net/articles/2010-12-25-tsearch2-for-rails-applications which covers how to get it working.