[open-ils-commits] r16816 - in trunk/Open-ILS: examples src/sql/Pg src/sql/Pg/upgrade (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Jun 25 13:31:25 EDT 2010
Author: miker
Date: 2010-06-25 13:31:21 -0400 (Fri, 25 Jun 2010)
New Revision: 16816
Added:
trunk/Open-ILS/src/sql/Pg/upgrade/0318.schema.authority-linking-ingest.sql
Modified:
trunk/Open-ILS/examples/fm_IDL.xml
trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
trunk/Open-ILS/src/sql/Pg/011.schema.authority.sql
trunk/Open-ILS/src/sql/Pg/030.schema.metabib.sql
Log:
add bib-authority linking table; add stored proc to extract linking; add hook to ingest (controlled by internal_flag) to implement authority link extraction
Modified: trunk/Open-ILS/examples/fm_IDL.xml
===================================================================
--- trunk/Open-ILS/examples/fm_IDL.xml 2010-06-25 16:00:36 UTC (rev 16815)
+++ trunk/Open-ILS/examples/fm_IDL.xml 2010-06-25 17:31:21 UTC (rev 16816)
@@ -1408,13 +1408,15 @@
<field name="last_xact_id" />
<field name="marc" />
<field name="source" />
- <field name="fixed_fields" oils_persist:virtual="true" />
- <field name="notes" oils_persist:virtual="true" />
+ <field name="fixed_fields" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field name="notes" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field name="bib_links" oils_persist:virtual="true" reporter:datatype="link"/>
</fields>
<links>
<link field="editor" reltype="has_a" key="id" map="" class="au"/>
<link field="creator" reltype="has_a" key="id" map="" class="au"/>
<link field="notes" reltype="has_many" key="record" map="" class="arn"/>
+ <link field="bib_links" reltype="has_many" key="authority" map="" class="abl"/>
<link field="fixed_fields" reltype="might_have" key="record" map="" class="ard"/>
</links>
</class>
@@ -1429,6 +1431,17 @@
<link field="record" reltype="has_a" key="id" map="" class="are"/>
</links>
</class>
+ <class id="abl" controller="open-ils.cstore" oils_obj:fieldmapper="authority::bib_linking" oils_persist:tablename="authority.bib_linking" reporter:label="Authority-Bibliographic Record Link">
+ <fields oils_persist:primary="id" oils_persist:sequence="authority.bib_linking_id_seq">
+ <field name="id" reporter:datatype="id" />
+ <field name="bib" reporter:datatype="link" />
+ <field name="authority" reporter:datatype="link" />
+ </fields>
+ <links>
+ <link field="bib" reltype="has_a" key="id" map="" class="bre"/>
+ <link field="authority" reltype="has_a" key="id" map="" class="are"/>
+ </links>
+ </class>
<class id="clm" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="config::language_map" oils_persist:tablename="config.language_map" reporter:label="Language Map" oils_persist:field_safe="true">
<fields oils_persist:primary="code" oils_persist:sequence="">
<field reporter:label="Language Code" name="code" reporter:selector="value" reporter:datatype="text"/>
@@ -1740,6 +1753,7 @@
<field reporter:label="Indexed Series Field Entries" name="series_field_entries" oils_persist:virtual="true" reporter:datatype="link"/>
<field reporter:label="Flattened MARC Fields " name="full_record_entries" oils_persist:virtual="true" reporter:datatype="link"/>
<field reporter:label="Simple Record Extracts " name="simple_record" oils_persist:virtual="true" reporter:datatype="link"/>
+ <field reporter:label="Authority Links" name="authority_links" oils_persist:virtual="true" reporter:datatype="link"/>
</fields>
<links>
<link field="owner" reltype="has_a" key="id" map="" class="aou"/>
@@ -1758,6 +1772,7 @@
<link field="author_field_entries" reltype="has_many" key="source" map="" class="mafe"/>
<link field="series_field_entries" reltype="has_many" key="source" map="" class="msefe"/>
<link field="full_record_entries" reltype="has_many" key="record" map="" class="mfr"/>
+ <link field="authority_links" reltype="has_many" key="bib" map="" class="abl"/>
</links>
<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
<actions>
Modified: trunk/Open-ILS/src/sql/Pg/002.schema.config.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-06-25 16:00:36 UTC (rev 16815)
+++ trunk/Open-ILS/src/sql/Pg/002.schema.config.sql 2010-06-25 17:31:21 UTC (rev 16816)
@@ -57,6 +57,7 @@
INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_metabib_full_rec');
INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_metabib_rec_descriptor');
INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_metabib_field_entry');
+INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_authority_linking');
CREATE TABLE config.global_flag (
label TEXT NOT NULL
@@ -68,7 +69,7 @@
install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
);
-INSERT INTO config.upgrade_log (version) VALUES ('0317'); -- miker
+INSERT INTO config.upgrade_log (version) VALUES ('0318'); -- miker
CREATE TABLE config.bib_source (
id SERIAL PRIMARY KEY,
Modified: trunk/Open-ILS/src/sql/Pg/011.schema.authority.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/011.schema.authority.sql 2010-06-25 16:00:36 UTC (rev 16815)
+++ trunk/Open-ILS/src/sql/Pg/011.schema.authority.sql 2010-06-25 17:31:21 UTC (rev 16816)
@@ -39,6 +39,14 @@
CREATE UNIQUE INDEX authority_record_unique_tcn ON authority.record_entry (arn_source,arn_value) WHERE deleted = FALSE OR deleted IS FALSE;
CREATE TRIGGER a_marcxml_is_well_formed BEFORE INSERT OR UPDATE ON authority.record_entry FOR EACH ROW EXECUTE PROCEDURE biblio.check_marcxml_well_formed();
+CREATE TABLE authority.bib_linking (
+ id BIGSERIAL PRIMARY KEY,
+ bib BIGINT NOT NULL REFERENCES biblio.record_entry (id),
+ authority BIGINT NOT NULL REFERENCES authority.record_entry (id)
+);
+CREATE INDEX authority_bl_bib_idx ON authority.bib_linking ( bib );
+CREATE UNIQUE INDEX authority_bl_bib_authority_once_idx ON authority.bib_linking ( authority, bib );
+
CREATE TABLE authority.record_note (
id BIGSERIAL PRIMARY KEY,
record BIGINT NOT NULL REFERENCES authority.record_entry (id) DEFERRABLE INITIALLY DEFERRED,
Modified: trunk/Open-ILS/src/sql/Pg/030.schema.metabib.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/030.schema.metabib.sql 2010-06-25 16:00:36 UTC (rev 16815)
+++ trunk/Open-ILS/src/sql/Pg/030.schema.metabib.sql 2010-06-25 17:31:21 UTC (rev 16816)
@@ -883,6 +883,18 @@
END;
$func$ LANGUAGE PLPGSQL;
+CREATE OR REPLACE FUNCTION biblio.map_authority_linking (bibid BIGINT, marc TEXT) RETURNS BIGINT AS $func$
+ DELETE FROM authority.bib_linking WHERE bib = $1;
+ INSERT INTO authority.bib_linking (bib, authority)
+ SELECT y.bib,
+ y.authority
+ FROM ( SELECT DISTINCT $1 AS bib,
+ BTRIM(remove_paren_substring(x))::BIGINT AS authority
+ FROM explode_array(oils_xpath('//*[@code="0"]/text()',$2)) x
+ ) y JOIN authority.record_entry r ON r.id = y.authority;
+ SELECT $1;
+$func$ LANGUAGE SQL;
+
-- AFTER UPDATE OR INSERT trigger for biblio.record_entry
CREATE OR REPLACE FUNCTION biblio.indexing_ingest_or_delete () RETURNS TRIGGER AS $func$
BEGIN
@@ -902,6 +914,12 @@
END IF;
+ -- Record authority linking
+ PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_linking' AND enabled;
+ IF NOT FOUND THEN
+ PERFORM biblio.map_authority_linking( NEW.id, NEW.marc );
+ END IF;
+
-- Flatten and insert the mfr data
PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_metabib_full_rec' AND enabled;
IF NOT FOUND THEN
Added: trunk/Open-ILS/src/sql/Pg/upgrade/0318.schema.authority-linking-ingest.sql
===================================================================
--- trunk/Open-ILS/src/sql/Pg/upgrade/0318.schema.authority-linking-ingest.sql (rev 0)
+++ trunk/Open-ILS/src/sql/Pg/upgrade/0318.schema.authority-linking-ingest.sql 2010-06-25 17:31:21 UTC (rev 16816)
@@ -0,0 +1,93 @@
+BEGIN;
+
+INSERT INTO config.upgrade_log (version) VALUES ('0318'); --miker
+
+INSERT INTO config.internal_flag (name) VALUES ('ingest.disable_authority_linking');
+
+CREATE TABLE authority.bib_linking (
+ id BIGSERIAL PRIMARY KEY,
+ bib BIGINT NOT NULL REFERENCES biblio.record_entry (id),
+ authority BIGINT NOT NULL REFERENCES authority.record_entry (id)
+);
+CREATE INDEX authority_bl_bib_idx ON authority.bib_linking ( bib );
+CREATE UNIQUE INDEX authority_bl_bib_authority_once_idx ON authority.bib_linking ( authority, bib );
+
+CREATE OR REPLACE FUNCTION biblio.map_authority_linking (bibid BIGINT, marc TEXT) RETURNS BIGINT AS $func$
+ DELETE FROM authority.bib_linking WHERE bib = $1;
+ INSERT INTO authority.bib_linking (bib, authority)
+ SELECT y.bib,
+ y.authority
+ FROM ( SELECT DISTINCT $1 AS bib,
+ BTRIM(remove_paren_substring(x))::BIGINT AS authority
+ FROM explode_array(oils_xpath('//*[@code="0"]/text()',$2)) x
+ ) y JOIN authority.record_entry r ON r.id = y.authority;
+ SELECT $1;
+$func$ LANGUAGE SQL;
+
+-- AFTER UPDATE OR INSERT trigger for biblio.record_entry
+CREATE OR REPLACE FUNCTION biblio.indexing_ingest_or_delete () RETURNS TRIGGER AS $func$
+BEGIN
+
+ IF NEW.deleted IS TRUE THEN -- If this bib is deleted
+ DELETE FROM metabib.metarecord_source_map WHERE source = NEW.id; -- Rid ourselves of the search-estimate-killing linkage
+ RETURN NEW; -- and we're done
+ END IF;
+
+ IF TG_OP = 'UPDATE' THEN -- re-ingest?
+ PERFORM * FROM config.internal_flag WHERE name = 'ingest.reingest.force_on_same_marc' AND enabled;
+
+ IF NOT FOUND AND OLD.marc = NEW.marc THEN -- don't do anything if the MARC didn't change
+ RETURN NEW;
+ END IF;
+
+
+ END IF;
+
+ -- Record authority linking
+ PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_authority_linking' AND enabled;
+ IF NOT FOUND THEN
+ PERFORM biblio.map_authority_linking( NEW.id, NEW.marc );
+ END IF;
+
+ -- Flatten and insert the mfr data
+ PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_metabib_full_rec' AND enabled;
+ IF NOT FOUND THEN
+ PERFORM metabib.reingest_metabib_full_rec(NEW.id);
+ PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_metabib_rec_descriptor' AND enabled;
+ IF NOT FOUND THEN
+ PERFORM metabib.reingest_metabib_rec_descriptor(NEW.id);
+ END IF;
+ END IF;
+
+ -- Gather and insert the field entry data
+ PERFORM metabib.reingest_metabib_field_entries(NEW.id);
+
+ -- Located URI magic
+ IF TG_OP = 'INSERT' THEN
+ PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_located_uri' AND enabled;
+ IF NOT FOUND THEN
+ PERFORM biblio.extract_located_uris( NEW.id, NEW.marc, NEW.editor );
+ END IF;
+ ELSE
+ PERFORM * FROM config.internal_flag WHERE name = 'ingest.disable_located_uri' AND enabled;
+ IF NOT FOUND THEN
+ PERFORM biblio.extract_located_uris( NEW.id, NEW.marc, NEW.editor );
+ END IF;
+ END IF;
+
+ -- (re)map metarecord-bib linking
+ IF TG_OP = 'INSERT' THEN -- if not deleted and performing an insert, check for the flag
+ PERFORM * FROM config.internal_flag WHERE name = 'ingest.metarecord_mapping.skip_on_insert' AND enabled;
+ IF NOT FOUND THEN
+ PERFORM metabib.remap_metarecord_for_bib( NEW.id, NEW.fingerprint );
+ END IF;
+ ELSE -- we're doing an update, and we're not deleted, remap
+ PERFORM metabib.remap_metarecord_for_bib( NEW.id, NEW.fingerprint );
+ END IF;
+
+ RETURN NEW;
+END;
+$func$ LANGUAGE PLPGSQL;
+
+COMMIT;
+
More information about the open-ils-commits
mailing list