[open-ils-commits] r16721 - in trunk/Open-ILS/src/sql/Pg: . upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Tue Jun 15 14:57:17 EDT 2010
Author: miker
Date: 2010-06-15 14:57:12 -0400 (Tue, 15 Jun 2010)
New Revision: 16721
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0309.schema.pre-index_vector-normalizers.sql
Modified:
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
Log:
support pre-indexing normalizers for facet value normalization (negative pos value in the field-norm map)
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-06-15 18:36:37 UTC (rev 16720)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-06-15 18:57:12 UTC (rev 16721)
@@ -68,7 +68,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0308'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0309'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
@@ -750,12 +750,36 @@
normalizer RECORD;
value TEXT := '';
BEGIN
+
+ value := NEW.value;
+
+ IF TG_TABLE_NAME::TEXT ~ 'field_entry$' THEN
+ FOR normalizer IN
+ SELECT n.func AS func,
+ n.param_count AS param_count,
+ 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 AND m.pos < 0
+ ORDER BY m.pos LOOP
+ EXECUTE 'SELECT ' || normalizer.func || '(' ||
+ quote_literal( value ) ||
+ CASE
+ WHEN normalizer.param_count > 0
+ THEN ',' || REPLACE(REPLACE(BTRIM(normalizer.params,'[]'),E'\'',E'\\\''),E'"',E'\'')
+ ELSE ''
+ END ||
+ ')' INTO value;
+
+ END LOOP;
+
+ NEW.value := value;
+ END IF;
+
IF NEW.index_vector = ''::tsvector THEN
RETURN NEW;
END IF;
- value := NEW.value;
-
IF TG_TABLE_NAME::TEXT ~ 'field_entry$' THEN
FOR normalizer IN
SELECT n.func AS func,
@@ -763,7 +787,7 @@
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
+ WHERE field = NEW.field AND m.pos >= 0
ORDER BY m.pos LOOP
EXECUTE 'SELECT ' || normalizer.func || '(' ||
quote_literal( value ) ||
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0309.schema.pre-index_vector-normalizers.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0309.schema.pre-index_vector-normalizers.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0309.schema.pre-index_vector-normalizers.sql 2010-06-15 18:57:12 UTC (rev 16721)
@@ -0,0 +1,72 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0309'); --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,
+ n.param_count AS param_count,
+ 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 AND m.pos < 0
+ ORDER BY m.pos LOOP
+ EXECUTE 'SELECT ' || normalizer.func || '(' ||
+ quote_literal( value ) ||
+ CASE
+ WHEN normalizer.param_count > 0
+ THEN ',' || REPLACE(REPLACE(BTRIM(normalizer.params,'[]'),E'\'',E'\\\''),E'"',E'\'')
+ ELSE ''
+ END ||
+ ')' INTO value;
+
+ END LOOP;
+
+ NEW.value := value;
+ END IF;
+
+ IF NEW.index_vector = ''::tsvector THEN
+ RETURN NEW;
+ END IF;
+
+ IF TG_TABLE_NAME::TEXT ~ 'field_entry$' THEN
+ FOR normalizer IN
+ SELECT n.func AS func,
+ n.param_count AS param_count,
+ 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 AND m.pos >= 0
+ ORDER BY m.pos LOOP
+ EXECUTE 'SELECT ' || normalizer.func || '(' ||
+ quote_literal( value ) ||
+ CASE
+ WHEN normalizer.param_count > 0
+ THEN ',' || REPLACE(REPLACE(BTRIM(normalizer.params,'[]'),E'\'',E'\\\''),E'"',E'\'')
+ ELSE ''
+ END ||
+ ')' 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