Drew R
Drew R

Reputation: 3088

Postgres - how to create text search index with weighted vectors?

Postgres doesn't to allow concatenating vectors in this fashion:

CREATE INDEX pgweb_idx ON pgweb USING
gin(
    setweight(to_tsvector('english', title),'A') ||
    setweight(to_tsvector('english', body), 'B')
);

gives

ERROR: syntax error at or near "||"

It allows this syntax in a select or update statement.

Is there a way to create a weighted full text index without adding a tvector column to the table?

Upvotes: 6

Views: 1452

Answers (1)

Jakub Kania
Jakub Kania

Reputation: 16487

I can't really offer a good explanation why it happens in this case however you can solve this problem by adding extra pair of parentheses around the expression

CREATE INDEX pgweb_idx ON pgweb USING
gin(
    (setweight(to_tsvector('english', title),'A') ||  setweight(to_tsvector('english', body), 'B'))
);

Upvotes: 10

Related Questions