- CREATE OR REPLACE FUNCTION public.create_plpgsql_language ()
- RETURNS TEXT
- AS $$
- CREATE LANGUAGE plpgsql;
- SELECT 'language plpgsql created'::TEXT;
- $$
- LANGUAGE 'sql';
-
- SELECT CASE WHEN
- (SELECT true::BOOLEAN
- FROM pg_language
- WHERE lanname='plpgsql')
- THEN
- (SELECT 'language already installed'::TEXT)
- ELSE
- (SELECT public.create_plpgsql_language())
- END;
-
- DROP FUNCTION public.create_plpgsql_language ();
-
- CREATE OR REPLACE FUNCTION node_ranking(node_id int, srch text) RETURNS float AS $$
- declare
- v tsvector;
- cv tsvector;
- rev_id int;
- child_count int;
- r record;
- begin
- SELECT active_revision_id INTO rev_id FROM forum_node WHERE id = node_id;
- SELECT tsv INTO v FROM forum_noderevision WHERE id = rev_id;
-
- SELECT count(*) INTO child_count FROM forum_node WHERE abs_parent_id = node_id AND NOT deleted;
-
- IF child_count > 0 THEN
- FOR r in SELECT * FROM forum_node WHERE abs_parent_id = node_id AND NOT deleted LOOP
- SELECT tsv INTO cv FROM forum_noderevision WHERE id = r.active_revision_id;
- v :=(v || cv);
+CREATE OR REPLACE FUNCTION public.create_plpgsql_language ()
+ RETURNS TEXT
+ AS $$
+ CREATE LANGUAGE plpgsql;
+ SELECT 'language plpgsql created'::TEXT;
+ $$
+LANGUAGE 'sql';
+
+SELECT CASE WHEN
+ (SELECT true::BOOLEAN
+ FROM pg_language
+ WHERE lanname='plpgsql')
+ THEN
+ (SELECT 'language already installed'::TEXT)
+ ELSE
+ (SELECT public.create_plpgsql_language())
+ END;
+
+DROP FUNCTION public.create_plpgsql_language ();
+
+CREATE OR REPLACE FUNCTION public.drop_tsv_noderevision_column () RETURNS VOID AS $$
+begin
+ ALTER TABLE forum_noderevision DROP COLUMN tsv;
+ DROP TRIGGER IF EXISTS tsvectorupdate ON forum_noderevision;
+end
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION public.tsv_noderevision_column_exists() RETURNS int AS $$
+ SELECT COUNT(attname)::int FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'forum_noderevision') AND attname = 'tsv';
+$$ LANGUAGE 'sql';
+
+select case when public.tsv_noderevision_column_exists()>0 then public.drop_tsv_noderevision_column()end;
+
+drop function drop_tsv_noderevision_column();
+drop function tsv_noderevision_column_exists();
+
+CREATE OR REPLACE FUNCTION set_doctable_tsv() RETURNS TRIGGER AS $$
+declare
+ root_id int;
+ doc tsvector;
+ rcount int;
+ cv tsvector;
+begin
+ SELECT abs_parent_id INTO root_id FROM forum_node WHERE id = new.node_id;
+
+ IF root_id IS NULL THEN
+ root_id := new.node_id;
+ END IF;
+
+ SELECT count(*)::int INTO rcount FROM forum_node WHERE id = root_id;
+
+ IF rcount = 0 THEN
+ return new;
+ END IF;
+
+ SELECT
+ setweight(to_tsvector('english', coalesce(tagnames,'')), 'A') ||
+ setweight(to_tsvector('english', coalesce(title,'')), 'B') ||
+ setweight(to_tsvector('english', coalesce(body,'')), 'C') INTO doc
+ FROM forum_node WHERE id = root_id;
+
+ SELECT count(*)::int INTO rcount FROM forum_node WHERE abs_parent_id = root_id AND (NOT state_string LIKE '%%deleted%%');
+
+ IF rcount > 0 THEN
+ 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
+ doc :=(doc || cv);