BEGIN; SET client_min_messages = 'ERROR'; -- Modification of th original MW 1.11 version. -- Now, it is possible to UPDATE a table with a NULL titlevector. This is important for -- the pagecontent table since only the most recent revision should to be indexed. -- Tsearch2 2 stuff. Will fail if we don't have proper access to the tsearch2 tables ALTER TABLE page ADD titlevector tsvector DEFAULT '{}'::tsvector; CREATE FUNCTION ts2_page_title() RETURNS TRIGGER LANGUAGE plpgsql AS $mw$ BEGIN IF TG_OP = 'INSERT' THEN NEW.titlevector = to_tsvector('default',NEW.page_title); ELSIF NEW.page_title != OLD.page_title AND NEW.titlevector IS NOT NULL THEN NEW.titlevector := to_tsvector('default',NEW.page_title); END IF; RETURN NEW; END; $mw$; CREATE TRIGGER ts2_page_title BEFORE INSERT OR UPDATE ON page FOR EACH ROW EXECUTE PROCEDURE ts2_page_title(); ALTER TABLE pagecontent ADD textvector tsvector DEFAULT '{}'::tsvector; CREATE FUNCTION ts2_page_text() RETURNS TRIGGER LANGUAGE plpgsql AS $mw$ BEGIN IF TG_OP = 'INSERT' THEN NEW.textvector = to_tsvector('default',NEW.old_text); ELSIF NEW.old_text != OLD.old_text AND NEW.textvector IS NOT NULL THEN NEW.textvector := to_tsvector('default',NEW.old_text); END IF; RETURN NEW; END; $mw$; CREATE TRIGGER ts2_page_text BEFORE INSERT OR UPDATE ON pagecontent FOR EACH ROW EXECUTE PROCEDURE ts2_page_text(); -- These are added by the setup script due to version compatibility issues -- If using 8.1, switch from "gin" to "gist" CREATE INDEX ts2_page_title ON page USING gist(titlevector); CREATE INDEX ts2_page_text ON pagecontent USING gist(textvector); COMMIT;