From 8602d3d8073eb66ff1dd19d0e534e43cdefb7f14 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 3 Jan 2012 16:41:42 -0500 Subject: [PATCH] Coded value map index normalizer New index normalizer which maps a coded value from the record to the display value configured in config.coded_value_map. The normalizer is applied with one parameter, the ctype of the coded_value_map to use for the mapping. E.g config.metabib_field_index_norm_map: id | field | norm | params | pos ---+-------+------+---------------+----- 57 | 31 | 17 | ["item_lang"] | -1 * pos = -1 causes this normalizer to be applied to facet_entry's This is primarily useful for facets. For example, you could create a metabib_field for language and mark it as a facet_field. Applying this index would allow the mapped language names (e.g. "French" instead of "fre") to display as facets. Signed-off-by: Bill Erickson Signed-off-by: Mike Rylander --- Open-ILS/src/sql/Pg/950.data.seed-values.sql | 8 ++++++++ Open-ILS/src/sql/Pg/999.functions.global.sql | 8 ++++++++ ...XXX.schema.coded-value-map-index-normalizer.sql | 24 ++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.schema.coded-value-map-index-normalizer.sql diff --git a/Open-ILS/src/sql/Pg/950.data.seed-values.sql b/Open-ILS/src/sql/Pg/950.data.seed-values.sql index 50b719214d..328372724e 100644 --- a/Open-ILS/src/sql/Pg/950.data.seed-values.sql +++ b/Open-ILS/src/sql/Pg/950.data.seed-values.sql @@ -7200,6 +7200,14 @@ INSERT INTO config.index_normalizer (name, description, func, param_count) VALUE 1 ); +INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES ( + 'Coded Value Map Normalizer', + 'Applies coded_value_map mapping of values', + 'coded_value_map_normalizer', + 1 +); + + -- make use of the index normalizers INSERT INTO config.metabib_field_index_norm_map (field,norm) diff --git a/Open-ILS/src/sql/Pg/999.functions.global.sql b/Open-ILS/src/sql/Pg/999.functions.global.sql index 9885876136..1acd06a62b 100644 --- a/Open-ILS/src/sql/Pg/999.functions.global.sql +++ b/Open-ILS/src/sql/Pg/999.functions.global.sql @@ -2085,3 +2085,11 @@ WHERE ORDER BY actor.org_unit_proximity(owner, $1) $$ LANGUAGE SQL; +CREATE OR REPLACE FUNCTION evergreen.coded_value_map_normalizer( input TEXT, ctype TEXT ) + RETURNS TEXT AS $F$ + SELECT COALESCE(value,$1) + FROM config.coded_value_map + WHERE ctype = $2 AND code = $1; +$F$ LANGUAGE SQL; + + diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.coded-value-map-index-normalizer.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.coded-value-map-index-normalizer.sql new file mode 100644 index 0000000000..2cc1c8046e --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.coded-value-map-index-normalizer.sql @@ -0,0 +1,24 @@ +-- Evergreen DB patch XXXX.schema.coded-value-map-index-normalizer.sql +-- +BEGIN; + +-- check whether patch can be applied +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +-- create the normalizer +CREATE OR REPLACE FUNCTION evergreen.coded_value_map_normalizer( input TEXT, ctype TEXT ) + RETURNS TEXT AS $F$ + SELECT COALESCE(value,$1) + FROM config.coded_value_map + WHERE ctype = $2 AND code = $1; +$F$ LANGUAGE SQL; + +-- register the normalizer +INSERT INTO config.index_normalizer (name, description, func, param_count) VALUES ( + 'Coded Value Map Normalizer', + 'Applies coded_value_map mapping of values', + 'coded_value_map_normalizer', + 1 +); + +COMMIT; -- 2.11.0