Browse Source

bug 6281: introduce LC::CallNumber::LC for sorting LC call numbers

This replaces the previous hand-coded normalizer.  Because
LC::CallNumber::LC appears to reject strings that aren't valid
LC call numbers, significant changes to the test cases were
made as well -- however, the one that really counts is the
last one which verifies the sorting.

To recalculate the call number sort key for each item, it is necessary
to run misc/maintenance/touch_all_items.pl

To test, create item records with the following call numbers, setting
the classification sort to 'lcc':

QC100 .U57 NO. 555 1986
QC145 .A57 V.12 1980
QC145.45 .H4 D65 1998
QC995 .E29 1997

Next, make a report of them in the inventory tool.  The items should be sorted
in the above order.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
new/bootstrap-opac
Galen Charlton 9 years ago
parent
commit
bc87274c66
  1. 19
      C4/ClassSortRoutine/LCC.pm
  2. 12
      t/ClassSortRoutine_LCC.t

19
C4/ClassSortRoutine/LCC.pm

@ -1,6 +1,7 @@
package C4::ClassSortRoutine::LCC;
# Copyright (C) 2007 LibLime
# Copyright (C) 2012 Equinox Software, Inc.
#
# This file is part of Koha.
#
@ -19,6 +20,7 @@ package C4::ClassSortRoutine::LCC;
use strict;
use warnings;
use Library::CallNumber::LC;
use vars qw($VERSION);
@ -50,19 +52,10 @@ sub get_class_sort_key {
$cn_class = '' unless defined $cn_class;
$cn_item = '' unless defined $cn_item;
my $key = uc "$cn_class $cn_item";
$key =~ s/^\s+//;
$key =~ s/\s+$//;
$key =~ s/^[^\p{IsAlnum}\s.]//g;
$key =~ s/^([A-Z]+)/$1 /;
$key =~ s/(\.[A-Z])/ $1/g;
# handle first digit group
$key =~ s/(\d+)/sprintf("%-05.5d", $1)/xe;
$key =~ s/\s+/_/g;
$key =~ s/\./_/g;
$key =~ s/__/_/g;
$key =~ s/[^\p{IsAlnum}_]//g;
my $call_number = Library::CallNumber::LC->new(uc "$cn_class $cn_item");
return '' unless defined $call_number;
my $key = $call_number->normalize();
$key = '' unless defined $key;
return $key;
}

12
t/ClassSortRoutine_LCC.t

@ -14,17 +14,17 @@ BEGIN {
#Obvious cases
is(C4::ClassSortRoutine::LCC::get_class_sort_key(), "", "No arguments returns an empty string");
is(C4::ClassSortRoutine::LCC::get_class_sort_key('a','b'), "A_B", "Arguments 'a','b' return 'A_B'");
is(C4::ClassSortRoutine::LCC::get_class_sort_key('a','b'), "A B", "Arguments 'a','b' return 'A B'");
#spaces in arguements
is(C4::ClassSortRoutine::LCC::get_class_sort_key(' ','b'), "B_", "Arguments ' ','b' return 'B_'");
is(C4::ClassSortRoutine::LCC::get_class_sort_key('a',' '), "A_", "Arguments 'a',' ' return 'A_'");
is(C4::ClassSortRoutine::LCC::get_class_sort_key(' ','b'), "B", "Arguments ' ','b' return 'B'");
is(C4::ClassSortRoutine::LCC::get_class_sort_key('a',' '), "A", "Arguments 'a',' ' return 'A'");
is(C4::ClassSortRoutine::LCC::get_class_sort_key(' ',' '), "", "Arguments ' ',' ' return ''");
#'funky cases' based on regex in code
is(C4::ClassSortRoutine::LCC::get_class_sort_key('.','b'), "_B", "Arguments '.','b' return '_B'");
is(C4::ClassSortRoutine::LCC::get_class_sort_key('....','........'), "_______", "Arguments '....','........' return '_______'");
is(C4::ClassSortRoutine::LCC::get_class_sort_key('.','.'), "__", "Arguments '.','.' return '__'");
is(C4::ClassSortRoutine::LCC::get_class_sort_key('.','b'), "", "Arguments '.','b' return ''");
is(C4::ClassSortRoutine::LCC::get_class_sort_key('....','........'), "", "Arguments '....','........' return ''");
is(C4::ClassSortRoutine::LCC::get_class_sort_key('.','.'), "", "Arguments '.','.' return ''");
# list of example call numbers -- these
# are intentionally in the _reverse_ of

Loading…
Cancel
Save