Coded value map index normalizer
authorBill Erickson <berick@esilibrary.com>
Tue, 3 Jan 2012 21:41:42 +0000 (16:41 -0500)
committerMike Rylander <mrylander@gmail.com>
Wed, 4 Jan 2012 15:33:26 +0000 (10:33 -0500)
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 <berick@esilibrary.com>
Signed-off-by: Mike Rylander <mrylander@gmail.com>

Open-ILS/src/sql/Pg/950.data.seed-values.sql
Open-ILS/src/sql/Pg/999.functions.global.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.schema.coded-value-map-index-normalizer.sql [new file with mode: 0644]

index 50b7192..3283727 100644 (file)
@@ -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)
index 9885876..1acd06a 100644 (file)
@@ -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 (file)
index 0000000..2cc1c80
--- /dev/null
@@ -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;