1 CREATE OR REPLACE FUNCTION public.create_plpgsql_language ()
4 CREATE LANGUAGE plpgsql;
5 SELECT 'language plpgsql created'::TEXT;
12 WHERE lanname='plpgsql')
14 (SELECT 'language already installed'::TEXT)
16 (SELECT public.create_plpgsql_language())
19 DROP FUNCTION public.create_plpgsql_language ();
21 CREATE OR REPLACE FUNCTION node_ranking(node_id int, srch text) RETURNS float AS $$
29 SELECT active_revision_id INTO rev_id FROM forum_node WHERE id = node_id;
30 SELECT tsv INTO v FROM forum_noderevision WHERE id = rev_id;
32 SELECT count(*) INTO child_count FROM forum_node WHERE abs_parent_id = node_id AND NOT deleted;
34 IF child_count > 0 THEN
35 FOR r in SELECT * FROM forum_node WHERE abs_parent_id = node_id AND NOT deleted LOOP
36 SELECT tsv INTO cv FROM forum_noderevision WHERE id = r.active_revision_id;
41 RETURN ts_rank_cd(v, plainto_tsquery('english', srch), 32);
45 CREATE OR REPLACE FUNCTION set_node_tsv() RETURNS TRIGGER AS $$
48 setweight(to_tsvector('english', coalesce(new.tagnames,'')), 'A') ||
49 setweight(to_tsvector('english', coalesce(new.title,'')), 'B') ||
50 setweight(to_tsvector('english', coalesce(new.body,'')), 'C');
56 CREATE OR REPLACE FUNCTION public.create_tsv_noderevision_column () RETURNS TEXT AS $$
58 ALTER TABLE forum_noderevision ADD COLUMN tsv tsvector;
60 DROP TRIGGER IF EXISTS tsvectorupdate ON forum_noderevision;
62 CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
63 ON forum_noderevision FOR EACH ROW EXECUTE PROCEDURE set_node_tsv();
65 CREATE INDEX noderevision_tsv ON forum_noderevision USING gin(tsv);
67 RETURN 'tsv column created'::TEXT;
72 (SELECT true::BOOLEAN FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'forum_noderevision') AND attname = 'tsv')
74 (SELECT 'Tsv column already exists'::TEXT)
76 (SELECT public.create_tsv_noderevision_column())
80 DROP FUNCTION public.create_tsv_noderevision_column();
82 UPDATE forum_noderevision SET id=id WHERE TRUE;