Skip to content

Instantly share code, notes, and snippets.

@lettergram
Created July 8, 2018 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lettergram/a248b1935fc90a6edfd5065f6e827bd6 to your computer and use it in GitHub Desktop.
Save lettergram/a248b1935fc90a6edfd5065f6e827bd6 to your computer and use it in GitHub Desktop.
CREATE FUNCTION comment_text_search_trigger() RETURNS trigger AS $$
begin
new.tsv_comment_text :=
setweight(to_tsvector(coalesce(new.story_title,'')), 'A') ||
setweight(to_tsvector(coalesce(new.comment_text,'')), 'B');
return new;
end
$$ LANGUAGE plpgsql;
/* Trigger on update */
CREATE TRIGGER tsvector_comment_text_update BEFORE INSERT OR UPDATE
ON comments FOR EACH ROW EXECUTE PROCEDURE comment_text_search_trigger();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment