1 ALTER TABLE question ADD COLUMN tsv tsvector;
\r
3 CREATE OR REPLACE FUNCTION public.create_plpgsql_language ()
\r
6 CREATE LANGUAGE plpgsql;
\r
7 SELECT 'language plpgsql created'::TEXT;
\r
12 (SELECT true::BOOLEAN
\r
14 WHERE lanname='plpgsql')
\r
16 (SELECT 'language already installed'::TEXT)
\r
18 (SELECT public.create_plpgsql_language())
\r
21 DROP FUNCTION public.create_plpgsql_language ();
\r
23 CREATE OR REPLACE FUNCTION set_question_tsv() RETURNS TRIGGER AS $$
\r
26 setweight(to_tsvector('english', coalesce(new.tagnames,'')), 'A') ||
\r
27 setweight(to_tsvector('english', coalesce(new.title,'')), 'B') ||
\r
28 setweight(to_tsvector('english', coalesce(new.summary,'')), 'C');
\r
31 $$ LANGUAGE plpgsql;
\r
33 CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
\r
34 ON question FOR EACH ROW EXECUTE PROCEDURE set_question_tsv();
\r
36 CREATE INDEX question_tsv ON question USING gin(tsv);
\r
38 UPDATE question SET title = title;
\r