From cb113702ae16d3e06af61f0a2a8ff6d650db04dd Mon Sep 17 00:00:00 2001
From: Jared Camins-Esakov <jcamins@cpbibliography.com>
Date: Mon, 25 Jun 2012 12:36:45 -0400
Subject: [PATCH] Bug 7475: Update configuration
In order to make matching rules more useful for MARC21 authorities,
this patch adds special indexes on previous see-from headings and
LCCN. This patch does not change UNIMARC authority configuration in
any way. Also modifies the Koha schema in preparation for adding
authority import and matching to the Staging tools.
To install:
1. Run installer/data/mysql/atomicupdate/importauthorities.pl
2. Update the following four files in your koha-dev:
etc/zebradb/authorities/etc/bib1.att
etc/zebradb/marc_defs/marc21/authorities/authority-koha-indexdefs.xml
etc/zebradb/marc_defs/marc21/authorities/authority-zebra-indexdefs.xsl
etc/zebradb/xsl/koha-indexdefs-to-zebra.xsl
3. Reindex your authorities:
misc/migration_tools/rebuild_zebra.pl -a -r -v
NOTE TO RM: this patch adds an atomicupdate file that needs to be
incorporated into updatedatabase.pl if bug 7167 is not pushed.
http://bugs.koha-community.org/show_bug.cgi?id=2060
Signed-off-by: Elliott Davis <elliott@bywatersolutions.com>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
Rebased on master 1 August 2012
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
Rebased on master 11 September 2012
---
etc/zebradb/authorities/etc/bib1.att | 1 +
.../authorities/authority-koha-indexdefs.xml | 16 +++++++
.../authorities/authority-zebra-indexdefs.xsl | 44 ++++++++++++++++++++
etc/zebradb/xsl/koha-indexdefs-to-zebra.xsl | 17 ++++++++
.../data/mysql/atomicupdate/importauthorities.pl | 26 ++++++++++++
installer/data/mysql/kohastructure.sql | 19 ++++++++-
6 files changed, 122 insertions(+), 1 deletions(-)
create mode 100755 installer/data/mysql/atomicupdate/importauthorities.pl
diff --git a/etc/zebradb/authorities/etc/bib1.att b/etc/zebradb/authorities/etc/bib1.att
index ef462f3..3e0f5fb 100644
--- a/etc/zebradb/authorities/etc/bib1.att
+++ b/etc/zebradb/authorities/etc/bib1.att
@@ -13,6 +13,7 @@ att 9042 Heading-use-subject-added-entry
att 9043 Kind-of-record
att 9046 Record-status
att 9050 Subject-heading-thesaurus
+att 9051 Previous-heading-see-from
# Personal Name
att 1 Personal-name
diff --git a/etc/zebradb/marc_defs/marc21/authorities/authority-koha-indexdefs.xml b/etc/zebradb/marc_defs/marc21/authorities/authority-koha-indexdefs.xml
index f1013e1..4599728 100644
--- a/etc/zebradb/marc_defs/marc21/authorities/authority-koha-indexdefs.xml
+++ b/etc/zebradb/marc_defs/marc21/authorities/authority-koha-indexdefs.xml
@@ -45,6 +45,19 @@ authority-zebra-indexdefs.xsl`
<kohaidx:index_control_field tag="008" offset="16" length="1">
<kohaidx:target_index>Heading-use-series-added-entry:w</kohaidx:target_index>
</kohaidx:index_control_field>
+
+ <!-- 010 LC Number -->
+ <kohaidx:index_subfields tag="010" subfields="az">
+ <kohaidx:target_index>LC-card-number:w</kohaidx:target_index>
+ <kohaidx:target_index>LC-card-number:p</kohaidx:target_index>
+ </kohaidx:index_subfields>
+
+ <!-- 040 cataloging agencies -->
+ <kohaidx:index_subfields tag="040" subfields="acd">
+ <kohaidx:target_index>Record-source:w</kohaidx:target_index>
+ <kohaidx:target_index>Record-source:p</kohaidx:target_index>
+ </kohaidx:index_subfields>
+
<!-- Personal name headings -->
<kohaidx:index_subfields tag="100" subfields="abcdefghjklmnopqrstvxyz">
@@ -346,6 +359,9 @@ authority-zebra-indexdefs.xsl`
<kohaidx:target_index>See-from:p</kohaidx:target_index>
<kohaidx:target_index>See-from:s</kohaidx:target_index>
</kohaidx:index_heading>
+ <kohaidx:index_heading_conditional tag="450" test="substring(marc:subfield[@code='w']/text(), 2, 1)" subfields="abvxyz" subdivisions="vxyz">
+ <kohaidx:target_index>Previous-heading-see-from:p</kohaidx:target_index>
+ </kohaidx:index_heading_conditional>
<kohaidx:index_match_heading tag="450" subfields="abvxyz" subdivisions="vxyz">
<kohaidx:target_index>Match:w</kohaidx:target_index>
<kohaidx:target_index>Match:p</kohaidx:target_index>
diff --git a/etc/zebradb/marc_defs/marc21/authorities/authority-zebra-indexdefs.xsl b/etc/zebradb/marc_defs/marc21/authorities/authority-zebra-indexdefs.xsl
index 6315316..1bafa16 100644
--- a/etc/zebradb/marc_defs/marc21/authorities/authority-zebra-indexdefs.xsl
+++ b/etc/zebradb/marc_defs/marc21/authorities/authority-zebra-indexdefs.xsl
@@ -13,6 +13,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
<xslo:template match="text()" mode="index_subfields"/>
<xslo:template match="text()" mode="index_data_field"/>
<xslo:template match="text()" mode="index_heading"/>
+ <xslo:template match="text()" mode="index_heading_conditional"/>
<xslo:template match="text()" mode="index_match_heading"/>
<xslo:template match="text()" mode="index_subject_thesaurus"/>
<xslo:template match="/">
@@ -35,6 +36,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
<xslo:apply-templates mode="index_subfields"/>
<xslo:apply-templates mode="index_data_field"/>
<xslo:apply-templates mode="index_heading"/>
+ <xslo:apply-templates mode="index_heading_conditional"/>
<xslo:apply-templates mode="index_match_heading"/>
<xslo:apply-templates mode="index_subject_thesaurus"/>
</z:record>
@@ -69,6 +71,24 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
<xslo:value-of select="substring(., 17, 1)"/>
</z:index>
</xslo:template>
+ <xslo:template mode="index_subfields" match="marc:datafield[@tag='010']">
+ <xslo:for-each select="marc:subfield">
+ <xslo:if test="contains('az', @code)">
+ <z:index name="LC-card-number:w LC-card-number:p">
+ <xslo:value-of select="."/>
+ </z:index>
+ </xslo:if>
+ </xslo:for-each>
+ </xslo:template>
+ <xslo:template mode="index_subfields" match="marc:datafield[@tag='040']">
+ <xslo:for-each select="marc:subfield">
+ <xslo:if test="contains('acd', @code)">
+ <z:index name="Record-source:w Record-source:p">
+ <xslo:value-of select="."/>
+ </z:index>
+ </xslo:if>
+ </xslo:for-each>
+ </xslo:template>
<xslo:template mode="index_subfields" match="marc:datafield[@tag='100']">
<xslo:for-each select="marc:subfield">
<xslo:if test="contains('abcdefghjklmnopqrstvxyz', @code)">
@@ -1102,6 +1122,30 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
<xslo:value-of select="normalize-space($raw_heading)"/>
</z:index>
</xslo:template>
+ <xslo:template mode="index_heading_conditional" match="marc:datafield[@tag='450']">
+ <xslo:if test="substring(marc:subfield[@code='w']/text(), 2, 1)">
+ <z:index name="Previous-heading-see-from:p">
+ <xslo:variable name="raw_heading">
+ <xslo:for-each select="marc:subfield">
+ <xslo:if test="contains('abvxyz', @code)" name="Previous-heading-see-from:p">
+ <xslo:if test="position() > 1">
+ <xslo:choose>
+ <xslo:when test="contains('vxyz', @code)">
+ <xslo:text>--</xslo:text>
+ </xslo:when>
+ <xslo:otherwise>
+ <xslo:value-of select="substring(' ', 1, 1)"/>
+ </xslo:otherwise>
+ </xslo:choose>
+ </xslo:if>
+ <xslo:value-of select="."/>
+ </xslo:if>
+ </xslo:for-each>
+ </xslo:variable>
+ <xslo:value-of select="normalize-space($raw_heading)"/>
+ </z:index>
+ </xslo:if>
+ </xslo:template>
<xslo:template mode="index_match_heading" match="marc:datafield[@tag='100']">
<z:index name="Match:w Match:p Match-heading:p Match-heading:s">
<xslo:variable name="raw_heading">
diff --git a/etc/zebradb/xsl/koha-indexdefs-to-zebra.xsl b/etc/zebradb/xsl/koha-indexdefs-to-zebra.xsl
index 59cae26..2316d3f 100644
--- a/etc/zebradb/xsl/koha-indexdefs-to-zebra.xsl
+++ b/etc/zebradb/xsl/koha-indexdefs-to-zebra.xsl
@@ -16,6 +16,7 @@
<xsl:key name="index_subfields_tag" match="kohaidx:index_subfields" use="@tag"/>
<xsl:key name="index_heading_tag" match="kohaidx:index_heading" use="@tag"/>
<xsl:key name="index_data_field_tag" match="kohaidx:index_data_field" use="@tag"/>
+ <xsl:key name="index_heading_conditional_tag" match="kohaidx:index_heading_conditional" use="@tag"/>
<xsl:key name="index_match_heading_tag" match="kohaidx:index_match_heading" use="@tag"/>
<xsl:template match="kohaidx:index_defs">
@@ -33,6 +34,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
<xslo:template match="text()" mode="index_subfields"/>
<xslo:template match="text()" mode="index_data_field"/>
<xslo:template match="text()" mode="index_heading"/>
+ <xslo:template match="text()" mode="index_heading_conditional"/>
<xslo:template match="text()" mode="index_match_heading"/>
<xslo:template match="text()" mode="index_subject_thesaurus"/>
<xslo:template match="/">
@@ -54,6 +56,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
<xslo:apply-templates mode="index_subfields"/>
<xslo:apply-templates mode="index_data_field"/>
<xslo:apply-templates mode="index_heading"/>
+ <xslo:apply-templates mode="index_heading_conditional"/>
<xslo:apply-templates mode="index_match_heading"/>
<xslo:apply-templates mode="index_subject_thesaurus"/>
</z:record>
@@ -64,6 +67,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
<xsl:call-template name="handle-index-subfields"/>
<xsl:call-template name="handle-index-data-field"/>
<xsl:call-template name="handle-index-heading"/>
+ <xsl:call-template name="handle-index-heading-conditional"/>
<xsl:call-template name="handle-index-match-heading"/>
<xsl:apply-templates/>
<xslo:template match="*">
@@ -279,6 +283,19 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
</xsl:for-each>
</xsl:template>
+ <xsl:template name="handle-index-heading-conditional">
+ <xsl:for-each select="//kohaidx:index_heading_conditional[generate-id() = generate-id(key('index_heading_conditional_tag', @tag)[1])]">
+ <xslo:template mode="index_heading_conditional">
+ <xslo:if>
+ <xsl:attribute name="test"><xsl:value-of select="@test"/></xsl:attribute>
+ <xsl:for-each select="key('index_heading_conditional_tag', @tag)">
+ <xsl:call-template name="handle-one-index-heading"/>
+ </xsl:for-each>
+ </xslo:if>
+ </xslo:template>
+ </xsl:for-each>
+ </xsl:template>
+
<xsl:template name="handle-one-data-field">
<xsl:variable name="indexes">
<xsl:call-template name="get-target-indexes"/>
diff --git a/installer/data/mysql/atomicupdate/importauthorities.pl b/installer/data/mysql/atomicupdate/importauthorities.pl
new file mode 100755
index 0000000..679235e
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/importauthorities.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use C4::Context;
+my $dbh = C4::Context->dbh;
+
+$dbh->do(
+q|CREATE TABLE `import_auths` (
+ import_record_id int(11) NOT NULL,
+ matched_authid int(11) default NULL,
+ control_number varchar(25) default NULL,
+ authorized_heading varchar(128) default NULL,
+ original_source varchar(25) default NULL,
+ CONSTRAINT import_auths_ibfk_1 FOREIGN KEY (import_record_id)
+ REFERENCES import_records (import_record_id) ON DELETE CASCADE ON UPDATE CASCADE,
+ KEY matched_authid (matched_authid)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;|
+);
+$dbh->do("ALTER TABLE import_batches
+ CHANGE COLUMN num_biblios num_records int(11) NOT NULL default 0,
+ ADD COLUMN record_type enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio'");
+$dbh->do("UPDATE import_batches SET record_type='auth' WHERE import_batch_id IN
+ (SELECT import_batch_id FROM import_records WHERE record_type='auth')");
+
+print "Upgrade done (Added support for staging authorities)\n";
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index 91d42a2..f02929c 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -855,7 +855,7 @@ CREATE TABLE `import_batches` ( -- information about batches of marc records tha
`matcher_id` int(11) default NULL, -- the id of the match rule used (matchpoints.matcher_id)
`template_id` int(11) default NULL,
`branchcode` varchar(10) default NULL,
- `num_biblios` int(11) NOT NULL default 0, -- number of bib records in the file
+ `num_records` int(11) NOT NULL default 0, -- number of records in the file
`num_items` int(11) NOT NULL default 0, -- number of items in the file
`upload_timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP, -- date and time the file was uploaded
`overlay_action` enum('replace', 'create_new', 'use_template', 'ignore') NOT NULL default 'create_new', -- how to handle duplicate records
@@ -863,6 +863,7 @@ CREATE TABLE `import_batches` ( -- information about batches of marc records tha
`item_action` enum('always_add', 'add_only_for_matches', 'add_only_for_new', 'ignore') NOT NULL default 'always_add', -- what to do with item records
`import_status` enum('staging', 'staged', 'importing', 'imported', 'reverting', 'reverted', 'cleaned') NOT NULL default 'staging', -- the status of the imported file
`batch_type` enum('batch', 'z3950', 'webservice') NOT NULL default 'batch', -- where this batch has come from
+ `record_type` enum('biblio', 'auth', 'holdings') NOT NULL default 'biblio', -- type of record in the batch
`file_name` varchar(100), -- the name of the file uploaded
`comments` mediumtext, -- any comments added when the file was uploaded
PRIMARY KEY (`import_batch_id`),
@@ -911,6 +912,22 @@ CREATE TABLE `import_record_matches` ( -- matches found when importing a batch o
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--
+-- Table structure for table `import_auths`
+--
+
+DROP TABLE IF EXISTS `import_auths`;
+CREATE TABLE `import_auths` (
+ `import_record_id` int(11) NOT NULL,
+ `matched_authid` int(11) default NULL,
+ `control_number` varchar(25) default NULL,
+ `authorized_heading` varchar(128) default NULL,
+ `original_source` varchar(25) default NULL,
+ CONSTRAINT `import_auths_ibfk_1` FOREIGN KEY (`import_record_id`)
+ REFERENCES `import_records` (`import_record_id`) ON DELETE CASCADE ON UPDATE CASCADE,
+ KEY `matched_authid` (`matched_authid`),
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+--
-- Table structure for table `import_biblios`
--
--
1.7.2.5