Skip to content


Subversion checkout URL

You can clone with
Download ZIP


tsvector_column and weighting #80

uberllama opened this Issue · 6 comments

3 participants


Hey guys. Am I right in that as soon as you leverage a tsvector_column, the weighting in the :against param no longer applies? This seems to be the case.

I have created a custom tsvector column and trigger in a migration as follows:

  pg_search_scope :search,
    :against => {:name => 'A', :description => 'B'},
    :using => {
      :tsearch => {
        :dictionary => "english",
        :tsvector_column => 'tsv_content_tsearch',
        :any_word => true
    execute "ALTER TABLE products ADD COLUMN tsv_content_tsearch tsvector"
    execute <<-QUERY
    UPDATE products SET tsv_content_tsearch = (to_tsvector('english', coalesce("products"."name"::text, '')) || 
                            to_tsvector('english', coalesce("products"."description"::text, '')));

    execute "CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
              ON products FOR EACH ROW EXECUTE PROCEDURE
              tsvector_update_trigger(tsv_content_tsearch, 'pg_catalog.english', name, description);""foo")
  Product Load (9.9ms)  SELECT "products".*, (ts_rank(("products"."tsv_content_tsearch"), (to_tsquery('english', ''' ' || 'foo' || ' ''')), 0)) AS pg_search_rank FROM "products" WHERE ((("products"."tsv_content_tsearch") @@ (to_tsquery('english', ''' ' || 'foo' || ' ''')))) ORDER BY pg_search_rank DESC, "products"."id" ASC

Does the weighting need to be moved into the tscvector column and trigger?



@uberllama have you found a solution? please close this issue if someone helped you outside github. thanks


Whew blast from the past! No I never got a reply as you can see.


Well, for some reason I found lots of out dated issues and I want to clean up issue tracker :-)


I can assume an answer at this point, which is that weighting does not in fact apply when using a TSV. Does that sound correct? :)


Maybe @nertzy could confirm.


I faced related issue and looks like you should manually create trigger function and set the weighting in its body like it described in It can't be automatically done because you describing weighting in Ruby code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.