-- Function: update_article_fts_index()
-- DROP FUNCTION update_article_fts_index();
CREATE OR REPLACE FUNCTION update_article_fts_index()
RETURNS trigger AS
$BODY$
BEGIN
-- Update the fts_index
NEW.fts_index =
setweight( to_tsvector( coalesce( (SELECT array_to_string(array(SELECT t.tag FROM articles_tags at JOIN tags t ON t.tag_id = at.tag_id WHERE at.article_id = NEW.article_id), ' ')) ,'')), 'A' ) || ' ' ||
setweight( to_tsvector( coalesce(NEW.title,'')), 'B' ) || ' ' ||
setweight( to_tsvector( coalesce(NEW.synopsis,'')), 'D' ) || ' ' ||
setweight( to_tsvector( coalesce(NEW.body,'')),'D');
-- Return the new row
RETURN NEW;
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION update_article_fts_index() OWNER TO think_done;