Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

tsvector_column and weighting #80

Open
uberllama opened this Issue · 5 comments

2 participants

@uberllama

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, '')));
    QUERY

    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);"
Product.search("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?

Cheers.

@giedriusr

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

@uberllama

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

@giedriusr

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

@uberllama

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? :)

@giedriusr

Maybe @nertzy could confirm.

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.