From 222c1ed372e20ef128a6a2afa0162532cbcbc49a Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@gmail.com>
Date: Thu, 4 Sep 2014 13:12:52 -0300
Subject: [PATCH] Bug 11232: UNIMARC facet definition and updated XSL file for
 DOM

This patch adds the facets definitions to the biblio-koha-indexdefs.xml, based
on what is hardcoded on C4::Koha::getFacets().

The biblio-zebra-indexdefs.xsl file for UNIMARC is generated using the usual:

xsltproc ...koha-indexdefs-to-zebra.xsl ...unimarc/biblios/biblio-koha-indexdefs.xml > \
    ...unimarc/biblios/biblio-zebra-indexdefs.xsl

Sponsored-by: Universidad Nacional de Cordoba
---
 .../unimarc/biblios/biblio-koha-indexdefs.xml      |  56 ++++++++
 .../unimarc/biblios/biblio-zebra-indexdefs.xsl     | 158 ++++++++++++++++++++-
 2 files changed, 212 insertions(+), 2 deletions(-)

diff --git a/etc/zebradb/marc_defs/unimarc/biblios/biblio-koha-indexdefs.xml b/etc/zebradb/marc_defs/unimarc/biblios/biblio-koha-indexdefs.xml
index aeeacc5..d0f7e46 100644
--- a/etc/zebradb/marc_defs/unimarc/biblios/biblio-koha-indexdefs.xml
+++ b/etc/zebradb/marc_defs/unimarc/biblios/biblio-koha-indexdefs.xml
@@ -1429,4 +1429,60 @@
     <target_index>totalissues:n</target_index>
     <target_index>totalissues:s</target_index>
   </index_subfields>
+
+  <facet tag="225" subfields="a">
+    <target_index>se:0</target_index>
+  </facet>
+  <facet tag="500" subfields="a">
+    <target_index>su-ut:0</target_index>
+  </facet>
+  <facet tag="501" subfields="a">
+    <target_index>su-ut:0</target_index>
+  </facet>
+  <facet tag="503" subfields="a">
+    <target_index>su-ut:0</target_index>
+  </facet>
+  <facet tag="600" subfields="ab">
+    <target_index>su-to:0</target_index>
+  </facet>
+  <facet tag="601" subfields="ab">
+    <target_index>su-to:0</target_index>
+  </facet>
+  <facet tag="602" subfields="a">
+    <target_index>su-to:0</target_index>
+  </facet>
+  <facet tag="604" subfields="at">
+    <target_index>su-to:0</target_index>
+  </facet>
+  <facet tag="605" subfields="a">
+    <target_index>su-to:0</target_index>
+  </facet>
+  <facet tag="606" subfields="ax">
+    <target_index>su-to:0</target_index>
+  </facet>
+  <facet tag="607" subfields="a">
+    <target_index>su-geo:0</target_index>
+  </facet>
+  <facet tag="610" subfields="a">
+    <target_index>su-to:0</target_index>
+  </facet>
+  <facet tag="700" subfields="ab">
+    <target_index>au:0</target_index>
+  </facet>
+  <facet tag="701" subfields="ab">
+    <target_index>au:0</target_index>
+  </facet>
+  <facet tag="702" subfields="ab">
+    <target_index>au:0</target_index>
+  </facet>
+  <facet tag="995" subfields="a">
+    <target_index>homebranch:0</target_index>
+  </facet>
+  <facet tag="995" subfields="b">
+    <target_index>holdingbranch:0</target_index>
+  </facet>
+  <facet tag="995" subfields="e">
+    <target_index>location:0</target_index>
+  </facet>
+
 </kohaidx:index_defs>
diff --git a/etc/zebradb/marc_defs/unimarc/biblios/biblio-zebra-indexdefs.xsl b/etc/zebradb/marc_defs/unimarc/biblios/biblio-zebra-indexdefs.xsl
index 46f106d..b00538c 100644
--- a/etc/zebradb/marc_defs/unimarc/biblios/biblio-zebra-indexdefs.xsl
+++ b/etc/zebradb/marc_defs/unimarc/biblios/biblio-zebra-indexdefs.xsl
@@ -12,6 +12,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
   <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_facets"/>
   <xslo:template match="text()" mode="index_heading"/>
   <xslo:template match="text()" mode="index_heading_conditional"/>
   <xslo:template match="text()" mode="index_match_heading"/>
@@ -35,6 +36,7 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
       <xslo:apply-templates/>
       <xslo:apply-templates mode="index_subfields"/>
       <xslo:apply-templates mode="index_data_field"/>
+      <xslo:apply-templates mode="index_facets"/>
       <xslo:apply-templates mode="index_heading"/>
       <xslo:apply-templates mode="index_heading_conditional"/>
       <xslo:apply-templates mode="index_match_heading"/>
@@ -436,8 +438,6 @@ definition file (probably something like {biblio,authority}-koha-indexdefs.xml)
         </z:index>
       </xslo:if>
     </xslo:for-each>
-  </xslo:template>
-  <xslo:template mode="index_subfields" match="marc:datafield[@tag='101']">
     <xslo:for-each select="marc:subfield">
       <xslo:if test="contains('c', @code)">
         <z:index name="language-original:w">
@@ -2500,6 +2500,160 @@ 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_facets" match="marc:datafield[@tag='225']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="se:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='500']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="su-ut:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='501']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="su-ut:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='503']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="su-ut:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='600']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="su-to:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+        <xslo:if test="marc:subfield[@code='a'] and marc:subfield[@code='b']">
+          <xslo:text>::*::</xslo:text>
+        </xslo:if>
+        <xslo:value-of select="marc:subfield[@code='b']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='601']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="su-to:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+        <xslo:if test="marc:subfield[@code='a'] and marc:subfield[@code='b']">
+          <xslo:text>::*::</xslo:text>
+        </xslo:if>
+        <xslo:value-of select="marc:subfield[@code='b']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='602']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="su-to:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='604']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="su-to:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+        <xslo:if test="marc:subfield[@code='a'] and marc:subfield[@code='t']">
+          <xslo:text>::*::</xslo:text>
+        </xslo:if>
+        <xslo:value-of select="marc:subfield[@code='t']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='605']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="su-to:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='606']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="su-to:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+        <xslo:if test="marc:subfield[@code='a'] and marc:subfield[@code='x']">
+          <xslo:text>::*::</xslo:text>
+        </xslo:if>
+        <xslo:value-of select="marc:subfield[@code='x']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='607']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="su-geo:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='610']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="su-to:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='700']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="au:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+        <xslo:if test="marc:subfield[@code='a'] and marc:subfield[@code='b']">
+          <xslo:text>::*::</xslo:text>
+        </xslo:if>
+        <xslo:value-of select="marc:subfield[@code='b']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='701']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="au:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+        <xslo:if test="marc:subfield[@code='a'] and marc:subfield[@code='b']">
+          <xslo:text>::*::</xslo:text>
+        </xslo:if>
+        <xslo:value-of select="marc:subfield[@code='b']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='702']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="au:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+        <xslo:if test="marc:subfield[@code='a'] and marc:subfield[@code='b']">
+          <xslo:text>::*::</xslo:text>
+        </xslo:if>
+        <xslo:value-of select="marc:subfield[@code='b']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='995']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="homebranch:0">
+        <xslo:value-of select="marc:subfield[@code='a']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='995']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="holdingbranch:0">
+        <xslo:value-of select="marc:subfield[@code='b']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
+  <xslo:template mode="index_facets" match="marc:datafield[@tag='995']">
+    <xslo:if test="not(@ind1='z')">
+      <z:index name="location:0">
+        <xslo:value-of select="marc:subfield[@code='e']"/>
+      </z:index>
+    </xslo:if>
+  </xslo:template>
   <xslo:template mode="index_all" match="text()">
     <z:index name="Any:w Any:p">
       <xslo:value-of select="."/>
-- 
1.9.1