Bug 7818: add index_data_field option to DOM indexing repertoire
authorGalen Charlton <gmc@esilibrary.com>
Mon, 26 Mar 2012 05:10:09 +0000 (01:10 -0400)
committerPaul Poulain <paul.poulain@biblibre.com>
Sat, 9 Jun 2012 09:44:04 +0000 (11:44 +0200)
Adds a new kohaidx:index_data_field index definition type which
indexes all of the subfields of a MARC data field as a single
phrase, separating the contents of each with a space.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jared Camins-Esakov <jcamins@cpbibliography.com>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
etc/zebradb/xsl/koha-indexdefs-to-zebra.xsl

index bfb79b4..3e3aed4 100644 (file)
@@ -15,6 +15,7 @@
     <xsl:key name="index_control_field_tag"   match="kohaidx:index_control_field"   use="@tag"/>
     <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_match_heading_tag" match="kohaidx:index_match_heading" use="@tag"/>
 
     <xsl:template match="kohaidx:index_defs">
@@ -30,6 +31,7 @@ authority-zebra-indexdefs.xsl` (substituting the appropriate file names).
             <xslo:output indent="yes" method="xml" version="1.0" encoding="UTF-8"/>
             <xslo:template match="text()"/>
             <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_match_heading"/>
             <xslo:template match="text()" mode="index_subject_thesaurus"/>
@@ -50,6 +52,7 @@ authority-zebra-indexdefs.xsl` (substituting the appropriate file names).
                     <xslo:attribute name="z:id"><xslo:value-of select="$controlField001"/></xslo:attribute>
                     <xslo:apply-templates/>
                     <xslo:apply-templates mode="index_subfields"/>
+                    <xslo:apply-templates mode="index_data_field"/>
                     <xslo:apply-templates mode="index_heading"/>
                     <xslo:apply-templates mode="index_match_heading"/>
                     <xslo:apply-templates mode="index_subject_thesaurus"/>
@@ -59,6 +62,7 @@ authority-zebra-indexdefs.xsl` (substituting the appropriate file names).
             <xsl:call-template name="handle-index-leader"/>
             <xsl:call-template name="handle-index-control-field"/>
             <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-match-heading"/>
             <xsl:apply-templates/>
@@ -260,6 +264,39 @@ authority-zebra-indexdefs.xsl` (substituting the appropriate file names).
             </xslo:for-each>
     </xsl:template>
 
+    <xsl:template name="handle-index-data-field">
+        <xsl:for-each select="//kohaidx:index_data_field[generate-id() = generate-id(key('index_data_field_tag', @tag)[1])]">
+            <xslo:template mode="index_data_field">
+                <xsl:attribute name="match">
+                    <xsl:text>marc:datafield[@tag='</xsl:text>
+                    <xsl:value-of select="@tag"/>
+                    <xsl:text>']</xsl:text>
+                </xsl:attribute>
+                <xsl:for-each select="key('index_data_field_tag', @tag)">
+                    <xsl:call-template name="handle-one-data-field"/>
+                </xsl:for-each>
+            </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"/>
+        </xsl:variable>
+        <z:index>
+            <xsl:attribute name="name"><xsl:value-of select="normalize-space($indexes)"/></xsl:attribute>
+            <xslo:variable name="raw_heading">
+                <xslo:for-each select="marc:subfield">
+                        <xslo:if test="position() > 1">
+                            <xslo:value-of select="substring(' ', 1, 1)"/> <!-- FIXME surely there's a better way  to specify a space -->
+                        </xslo:if>
+                        <xslo:value-of select="."/>
+                </xslo:for-each>
+            </xslo:variable>
+            <xslo:value-of select="normalize-space($raw_heading)"/>
+        </z:index>
+    </xsl:template>
+
     <xsl:template name="handle-index-heading">
         <xsl:for-each select="//kohaidx:index_heading[generate-id() = generate-id(key('index_heading_tag', @tag)[1])]">
             <xslo:template mode="index_heading">