Bug 17547: (MARC21|NORMARC) have Chronological term field $9 indexed
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 2 Dec 2016 20:16:10 +0000 (17:16 -0300)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 16 Dec 2016 11:27:18 +0000 (11:27 +0000)
This patch makes Zebra index the 648$9 link for chronological terms on
bibliographic records. This way an authority search on chronological terms
will show the right number in 'Used in X records' message.

To test:
- Have a record with a 648 field, linked to an authority record (i.e. with an authid on 648$9).
- Search for the record, notice it is indexed.
- Perform an authority search for the chronological term
=> FAIL: the term is linked to our record, but koha shows '0' count.
- Apply the patch
- Run:
  $ cd kohaclone
  $ xsltproc etc/zebra/xsl/koha-indexdefs-to-zebra.xsl \
       etc/zebradb/marc_defs/marc21/biblios/biblio-koha-indexdefs.xml \
     > etc/zebradb/marc_defs/marc21/biblios/biblio-zebra-indexdefs.xsl
  $ git diff
=> SUCCESS: Notice the shipped etc/zebradb/marc_defs/marc21/biblios/biblio-zebra-indexdefs.xsl
   is up-to-date
- Run:
  $ sudo cp etc/zebradb/marc_defs/marc21/biblios/biblio-zebra-indexdefs.xsl \
            /etc/koha/zebradb/marc_defs/marc21/biblios/biblio-zebra-indexdefs.xsl
  $ sudo koha-restart-zebra kohadev
  $ sudo koha-rebuild-zebra -f -b -v kohadev
- Search for the record, notice it is indexed.
- Perform an authority search for the chronological term
=> SUCCESS: the term is linked to our record, usage count is 1
- Sign off :-D

I assume NORMARC is similar on this regard. Feel free to fail it if the NORMARC part of the
patch is wrong.

Sponsored-by: Universidad Nacional de Cordoba

Signed-off-by: Hugo Agud <hagud@orex.es>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

etc/zebradb/marc_defs/marc21/biblios/biblio-koha-indexdefs.xml
etc/zebradb/marc_defs/marc21/biblios/biblio-zebra-indexdefs.xsl
etc/zebradb/marc_defs/normarc/biblios/biblio-koha-indexdefs.xml
etc/zebradb/marc_defs/normarc/biblios/biblio-zebra-indexdefs.xsl

index 38f91a2..49f774a 100644 (file)
     <target_index>Subject:w</target_index>
     <target_index>Subject:p</target_index>
   </index_data_field>
+  <index_subfields tag="648" subfields="9">
+    <target_index>Koha-Auth-Number:w</target_index>
+  </index_subfields>
   <!--record.abs line 177: melm 650$9      Koha-Auth-Number    -->
   <index_subfields tag="650" subfields="9">
     <target_index>Koha-Auth-Number:w</target_index>
index dd2a760..5feab04 100644 (file)
@@ -628,6 +628,15 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
       </xslo:if>
     </xslo:for-each>
   </xslo:template>
+  <xslo:template mode="index_subfields" match="marc:datafield[@tag='648']">
+    <xslo:for-each select="marc:subfield">
+      <xslo:if test="contains('9', @code)">
+        <z:index name="Koha-Auth-Number:w">
+          <xslo:value-of select="."/>
+        </z:index>
+      </xslo:if>
+    </xslo:for-each>
+  </xslo:template>
   <xslo:template mode="index_subfields" match="marc:datafield[@tag='650']">
     <xslo:for-each select="marc:subfield">
       <xslo:if test="contains('9', @code)">
index 0918f2a..dff2d75 100644 (file)
     <target_index>Subject:w</target_index>
     <target_index>Subject:p</target_index>
   </index_data_field>
+  <index_subfields tag="648" subfields="9">
+    <target_index>Koha-Auth-Number:w</target_index>
+  </index_subfields>
   <!--record.abs line 199: melm 650$9      Koha-Auth-Number-->
   <index_subfields tag="650" subfields="9">
     <target_index>Koha-Auth-Number:w</target_index>
index 1eeca69..301f9a7 100644 (file)
@@ -17,6 +17,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
   <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="text()" mode="index_sort_tit"/>
   <xslo:template match="/">
     <xslo:if test="marc:collection">
       <collection>
@@ -42,6 +43,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
       <xslo:apply-templates mode="index_match_heading"/>
       <xslo:apply-templates mode="index_subject_thesaurus"/>
       <xslo:apply-templates mode="index_all"/>
+      <xslo:apply-templates mode="index_sort_tit"/>
     </z:record>
   </xslo:template>
   <xslo:template match="marc:leader">
@@ -409,6 +411,15 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
       </xslo:if>
     </xslo:for-each>
   </xslo:template>
+  <xslo:template mode="index_subfields" match="marc:datafield[@tag='648']">
+    <xslo:for-each select="marc:subfield">
+      <xslo:if test="contains('9', @code)">
+        <z:index name="Koha-Auth-Number:w">
+          <xslo:value-of select="."/>
+        </z:index>
+      </xslo:if>
+    </xslo:for-each>
+  </xslo:template>
   <xslo:template mode="index_subfields" match="marc:datafield[@tag='650']">
     <xslo:for-each select="marc:subfield">
       <xslo:if test="contains('9', @code)">
@@ -1855,6 +1866,19 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
       <xslo:value-of select="."/>
     </z:index>
   </xslo:template>
+  <xslo:template mode="index_sort_tit" match="marc:datafield[@tag='245']">
+    <xslo:variable name="chop">
+      <xslo:choose>
+        <xslo:when test="not(number(@ind2))">0</xslo:when>
+        <xslo:otherwise>
+          <xslo:value-of select="number(@ind2)"/>
+        </xslo:otherwise>
+      </xslo:choose>
+    </xslo:variable>
+    <z:index name="Title:s">
+      <xslo:value-of select="substring(marc:subfield[@code='a'], $chop+1)"/>
+    </z:index>
+  </xslo:template>
   <xslo:template name="chopPunctuation">
     <xslo:param name="chopString"/>
     <xslo:variable name="length" select="string-length($chopString)"/>