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 public.drop_tsv_noderevision_column () RETURNS VOID AS $$
23 ALTER TABLE forum_noderevision DROP COLUMN tsv;
24 DROP TRIGGER IF EXISTS tsvectorupdate ON forum_noderevision;
28 CREATE OR REPLACE FUNCTION public.tsv_noderevision_column_exists() RETURNS int AS $$
29 SELECT COUNT(attname)::int FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'forum_noderevision') AND attname = 'tsv';
32 select case when public.tsv_noderevision_column_exists()>0 then public.drop_tsv_noderevision_column()end;
34 drop function drop_tsv_noderevision_column();
35 drop function tsv_noderevision_column_exists();
37 CREATE OR REPLACE FUNCTION set_doctable_tsv() RETURNS TRIGGER AS $$
44 SELECT abs_parent_id INTO root_id FROM forum_node WHERE id = new.node_id;
46 IF root_id IS NULL THEN
47 root_id := new.node_id;
50 SELECT count(*)::int INTO rcount FROM forum_node WHERE id = root_id;
57 setweight(to_tsvector('english', coalesce(tagnames,'')), 'A') ||
58 setweight(to_tsvector('english', coalesce(title,'')), 'B') ||
59 setweight(to_tsvector('english', coalesce(body,'')), 'C') INTO doc
60 FROM forum_node WHERE id = root_id;
62 SELECT count(*)::int INTO rcount FROM forum_node WHERE abs_parent_id = root_id AND (NOT state_string LIKE '%%deleted%%');
65 FOR cv in SELECT setweight(to_tsvector('english', coalesce(body,'')), 'C') FROM forum_node WHERE abs_parent_id = root_id AND (NOT state_string LIKE '%%deleted%%') LOOP
70 SELECT count(*)::int INTO rcount FROM forum_rootnode_doc WHERE node_id = root_id;
73 UPDATE forum_rootnode_doc SET document = doc WHERE node_id = root_id;
75 INSERT INTO forum_rootnode_doc (node_id, document) VALUES (root_id, doc);
82 CREATE OR REPLACE FUNCTION public.build_doc_table() RETURNS VOID as $$
83 CREATE TABLE forum_rootnode_doc
87 PRIMARY KEY (node_id),
88 FOREIGN KEY (node_id) REFERENCES forum_node (id) ON UPDATE NO ACTION ON DELETE NO ACTION
91 DROP TRIGGER IF EXISTS tsvectorupdate ON forum_noderevision;
93 CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
94 ON forum_noderevision FOR EACH ROW EXECUTE PROCEDURE set_doctable_tsv();
96 CREATE INDEX doctable_tsv ON forum_rootnode_doc USING gin(document);
99 CREATE OR REPLACE FUNCTION public.doc_table_exists() RETURNS int AS $$
100 SELECT COUNT(table_name)::int FROM information_schema.tables WHERE table_name = 'forum_rootnode_doc';
103 select case when public.doc_table_exists()=0 then public.build_doc_table()end;
105 drop function build_doc_table();
106 drop function doc_table_exists();
108 CREATE OR REPLACE FUNCTION rank_exact_matches(rank float) RETURNS float AS $$
119 ALTER table forum_rootnode_doc DISABLE TRIGGER ALL;
120 UPDATE forum_noderevision SET id = id WHERE TRUE;