create version of authority.extract_headings() that can accept marcxml
authorGalen Charlton <gmc@equinoxinitiative.org>
Fri, 13 Jan 2017 20:04:54 +0000 (15:04 -0500)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 13 Jan 2017 20:04:54 +0000 (15:04 -0500)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/sql/Pg/upgrade/YYYY.schema.authority.sql

index 931ce7a..fd5a123 100644 (file)
@@ -101,9 +101,8 @@ CREATE TYPE authority.heading AS (
     normalized_heading  TEXT
 );
 
-CREATE OR REPLACE FUNCTION authority.extract_headings(rid BIGINT) RETURNS SETOF authority.heading AS $func$
+CREATE OR REPLACE FUNCTION authority.extract_headings(marc TEXT) RETURNS SETOF authority.heading AS $func$
 DECLARE
-    auth        authority.record_entry%ROWTYPE;
     idx         authority.heading_field%ROWTYPE;
     xfrm        config.xml_transform%ROWTYPE;
     prev_xfrm   TEXT;
@@ -122,9 +121,6 @@ DECLARE
     output_row  authority.heading;
 BEGIN
 
-    -- Get the record
-    SELECT INTO auth * FROM authority.record_entry WHERE id = rid;
-
     -- Loop over the indexing entries
     FOR idx IN SELECT * FROM authority.heading_field ORDER BY format LOOP
 
@@ -140,9 +136,9 @@ BEGIN
         IF prev_xfrm IS NULL OR prev_xfrm <> xfrm.name THEN
             -- Can't skip the transform
             IF xfrm.xslt <> '---' THEN
-                transformed_xml := oils_xslt_process(auth.marc, xfrm.xslt);
+                transformed_xml := oils_xslt_process(marc, xfrm.xslt);
             ELSE
-                transformed_xml := auth.marc;
+                transformed_xml := marc;
             END IF;
 
             prev_xfrm := xfrm.name;
@@ -243,6 +239,18 @@ BEGIN
 END;
 $func$ LANGUAGE PLPGSQL;
 
+CREATE OR REPLACE FUNCTION authority.extract_headings(rid BIGINT) RETURNS SETOF authority.heading AS $func$
+DECLARE
+    auth        authority.record_entry%ROWTYPE;
+    output_row  authority.heading;
+BEGIN
+    -- Get the record
+    SELECT INTO auth * FROM authority.record_entry WHERE id = rid;
+
+    RETURN QUERY SELECT * FROM authority.extract_headings(auth.marc);
+END;
+$func$ LANGUAGE PLPGSQL;
+
 ALTER TABLE authority.control_set_authority_field ADD COLUMN heading_field INTEGER REFERENCES authority.heading_field(id);
 
 UPDATE authority.control_set_authority_field acsaf