[open-ils-commits] r14402 - in trunk/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Oct 13 15:06:30 EDT 2009
Author: miker
Date: 2009-10-13 15:06:25 -0400 (Tue, 13 Oct 2009)
New Revision: 14402
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0034.schema.in-db-indexing-normalization.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
Log:
add a replacement oils_tsearch2() trigger function that will use any configured in-db indexing normalizers
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-10-13 18:22:42 UTC (rev 14401)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2009-10-13 19:06:25 UTC (rev 14402)
@@ -51,7 +51,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0033'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0034'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
@@ -595,6 +595,35 @@
pos INT NOT NULL DEFAULT 0
);
+CREATE OR REPLACE FUNCTION oils_tsearch2 () RETURNS TRIGGER AS $$
+DECLARE
+ normalizer RECORD;
+ value TEXT := '';
+BEGIN
+ value := NEW.value;
+ IF TG_TABLE_NAME::TEXT ~ 'field_entry$' THEN
+ FOR normalizer IN
+ SELECT n.func AS func,
+ m.params AS params
+ FROM config.index_normalizer n
+ JOIN config.metabib_field_index_norm_map m ON (m.norm = n.id)
+ WHERE field = NEW.field
+ ORDER BY m.pos
+ LOOP
+ EXECUTE 'SELECT ' || normalizer.func || '(' || quote_literal( value ) || ',' || BTRIM(normalizer.params,'[]') || ')' INTO value;
+ END LOOP;
+ END IF;
+
+ IF REGEXP_REPLACE(VERSION(),E'^.+?(\\d+\\.\\d+).*?$',E'\\1')::FLOAT > 8.2 THEN
+ NEW.index_vector = to_tsvector((TG_ARGV[0])::regconfig, value);
+ ELSE
+ NEW.index_vector = to_tsvector(TG_ARGV[0], value);
+ END IF;
+
+ RETURN NEW;
+END;
+$$ LANGUAGE PLPGSQL;
+
COMMIT;
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0034.schema.in-db-indexing-normalization.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0034.schema.in-db-indexing-normalization.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0034.schema.in-db-indexing-normalization.sql 2009-10-13 19:06:25 UTC (rev 14402)
@@ -0,0 +1,36 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0034'); -- miker
+
+CREATE OR REPLACE FUNCTION oils_tsearch2 () RETURNS TRIGGER AS $$
+DECLARE
+ normalizer RECORD;
+ value TEXT := '';
+BEGIN
+ value := NEW.value;
+
+ IF TG_TABLE_NAME::TEXT ~ 'field_entry$' THEN
+ FOR normalizer IN
+ SELECT n.func AS func,
+ m.params AS params
+ FROM config.index_normalizer n
+ JOIN config.metabib_field_index_norm_map m ON (m.norm = n.id)
+ WHERE field = NEW.field
+ ORDER BY m.pos
+ LOOP
+ EXECUTE 'SELECT ' || normalizer.func || '(' || quote_literal( value ) || ',' || BTRIM(normalizer.params,'[]') || ')' INTO value;
+ END LOOP;
+ END IF;
+
+ IF REGEXP_REPLACE(VERSION(),E'^.+?(\\d+\\.\\d+).*?$',E'\\1')::FLOAT > 8.2 THEN
+ NEW.index_vector = to_tsvector((TG_ARGV[0])::regconfig, value);
+ ELSE
+ NEW.index_vector = to_tsvector(TG_ARGV[0], value);
+ END IF;
+
+ RETURN NEW;
+END;
+$$ LANGUAGE PLPGSQL;
+
+COMMIT;
+
More information about the open-ils-commits
mailing list