Bug 7617: Sort authority results by authid
authorJared Camins-Esakov <jcamins@cpbibliography.com>
Sun, 11 Mar 2012 17:48:43 +0000 (13:48 -0400)
committerPaul Poulain <paul.poulain@biblibre.com>
Thu, 29 Mar 2012 09:04:58 +0000 (11:04 +0200)
Add the option of sorting authority search results by authid, and instruct the
FirstMatch and LastMatch linkers to use that sort order rather than the default
search order.

To test:
1. Install new Zebra authorities config
    etc/zebradb/marc_defs/marc21/authorities/authority-koha-indexdefs.xml,
    etc/zebradb/marc_defs/marc21/authorities/authority-zebra-indexdefs.xsl,
    etc/zebradb/marc_defs/marc21/authorities/record.abs, and
    etc/zebradb/marc_defs/unimarc/authorities/record.abs
2. Reindex authorities in Zebra
3. Set LinkerModule to FirstMatch or LastMatch
4. Add two identical authority records, and a bib record with a heading that
   matches them
5. Run misc/link_bibs_to_authorities.pl on that record
6. Confirm that the authid that's been inserted into subfield $9 of that
   heading is the first, if you selected FirstMatch, or last if you selected
   LastMatch

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
I followed the test plan and checked that for "Last match" and "First match"
the correct authority was selected and linked to the record.

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
C4/AuthoritiesMarc.pm
C4/Heading.pm
etc/zebradb/marc_defs/marc21/authorities/authority-koha-indexdefs.xml
etc/zebradb/marc_defs/marc21/authorities/authority-zebra-indexdefs.xsl
etc/zebradb/marc_defs/marc21/authorities/record.abs
etc/zebradb/marc_defs/unimarc/authorities/record.abs

index f35b885..703ea75 100644 (file)
@@ -279,13 +279,16 @@ sub SearchAuthorities {
         }
         ## Adding order
         #$query=' @or  @attr 7=2 @attr 1=Heading 0 @or  @attr 7=1 @attr 1=Heading 1'.$query if ($sortby eq "HeadingDsc");
-        my $orderstring= ($sortby eq "HeadingAsc"?
-                           '@attr 7=1 @attr 1=Heading 0'
-                         :
-                           $sortby eq "HeadingDsc"?      
-                            '@attr 7=2 @attr 1=Heading 0'
-                           :''
-                        );            
+        my $orderstring;
+        if ($sortby eq 'HeadingAsc') {
+            $orderstring = '@attr 7=1 @attr 1=Heading 0';
+        } elsif ($sortby eq 'HeadingDsc') {
+            $orderstring = '@attr 7=2 @attr 1=Heading 0';
+        } elsif ($sortby eq 'AuthidAsc') {
+            $orderstring = '@attr 7=1 @attr 1=Local-Number 0';
+        } elsif ($sortby eq 'AuthidDsc') {
+            $orderstring = '@attr 7=2 @attr 1=Local-Number 0';
+        }
         $query=($query?$query:"\@attr 1=_ALLRECORDS \@attr 2=103 ''");
         $query="\@or $orderstring $query" if $orderstring;
 
index 98bb4a8..102cac6 100644 (file)
@@ -205,7 +205,7 @@ sub _search {
     return C4::AuthoritiesMarc::SearchAuthorities(
         \@marclist, \@and_or, \@excluding, \@operator,
         \@value,    0,        20,          $self->{'auth_type'},
-        '',         $skipmetadata
+        'AuthidAsc',         $skipmetadata
     );
 }
 
index 67b234f..f1013e1 100644 (file)
@@ -23,6 +23,7 @@ authority-zebra-indexdefs.xsl`
   <!-- Original record ID -->
   <kohaidx:index_control_field tag="001">
     <kohaidx:target_index>Local-Number:w</kohaidx:target_index>
+    <kohaidx:target_index>Local-Number:s</kohaidx:target_index>
   </kohaidx:index_control_field>
   
   <!-- 008 -->
index 3ee5d6c..aa02e70 100644 (file)
@@ -46,7 +46,7 @@ authority-zebra-indexdefs.xsl` (substituting the appropriate file names).
     </z:index>
   </xslo:template>
   <xslo:template match="marc:controlfield[@tag='001']">
-    <z:index name="Local-Number:w">
+    <z:index name="Local-Number:w Local-Number:s">
       <xslo:value-of select="."/>
     </z:index>
   </xslo:template>
index 5baa5b2..23d75a2 100644 (file)
@@ -11,7 +11,7 @@ systag sysno rank
 xpath enable
 
 all any
-melm 001 Local-Number
+melm 001 Local-Number,Local-Number:s
 melm 942$a authtype:w,authtype:p
 
 # Personal Name
index 92f742b..18245c0 100644 (file)
@@ -11,7 +11,7 @@ systag sysno rank
 xpath enable
 
 all any
-melm 001 Local-Number
+melm 001 Local-Number,Local-Number:s
 melm 942$a authtype
 melm 152$b authtype:w,authtype:p