From: James Fournie Date: Sun, 11 Dec 2011 00:49:01 +0000 (-0800) Subject: Fix Dewey call number sorting X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=a769d4798a3b0500825d1cb3082f73d7e1a2c6b3;p=evergreen%2Fpines.git Fix Dewey call number sorting Ported over Koha commit aef8358c - fix for Koha Bug 4265. Further documented in Evergreen LP # 902667 Here's the description from the commit message by Magnus Enger: C4::ClassSortRoutine::Dewey turns "306 Les" into "306_Les" for items.cn_sort and MARC-field 952$6, which results in "306.46 Les" being sorted before "306 Les" in the OPAC. With this patch, "306 Les" is turned into "306_000000000000000_Les". Signed-off-by: James Fournie Signed-off-by: Dan Scott --- diff --git a/Open-ILS/src/sql/Pg/040.schema.asset.sql b/Open-ILS/src/sql/Pg/040.schema.asset.sql index f80b2d11fb..fef5ced149 100644 --- a/Open-ILS/src/sql/Pg/040.schema.asset.sql +++ b/Open-ILS/src/sql/Pg/040.schema.asset.sql @@ -328,6 +328,10 @@ CREATE OR REPLACE FUNCTION asset.label_normalizer_dewey(TEXT) RETURNS TEXT AS $f } } } + # Pad the first digit_group if there was only one + if (1 == $digit_group_count) { + $tokens[0] .= '_000000000000000' + } my $key = join("_", @tokens); $key =~ s/[^\p{IsAlnum}_]//g; diff --git a/Open-ILS/src/sql/Pg/upgrade/xxxx.dewey-sort-fix.sql b/Open-ILS/src/sql/Pg/upgrade/xxxx.dewey-sort-fix.sql new file mode 100644 index 0000000000..310bb2f16e --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/xxxx.dewey-sort-fix.sql @@ -0,0 +1,43 @@ +BEGIN; + +INSERT INTO config.upgrade_log (version) VALUES ('xxxx'); + +CREATE OR REPLACE FUNCTION asset.label_normalizer_dewey(TEXT) RETURNS TEXT AS $func$ + # Derived from the Koha C4::ClassSortRoutine::Dewey module + # Copyright (C) 2007 LibLime + # Licensed under the GPL v2 or later + + use strict; + use warnings; + + my $init = uc(shift); + $init =~ s/^\s+//; + $init =~ s/\s+$//; + $init =~ s!/!!g; + $init =~ s/^([\p{IsAlpha}]+)/$1 /; + my @tokens = split /\.|\s+/, $init; + my $digit_group_count = 0; + for (my $i = 0; $i <= $#tokens; $i++) { + if ($tokens[$i] =~ /^\d+$/) { + $digit_group_count++; + if (2 == $digit_group_count) { + $tokens[$i] = sprintf("%-15.15s", $tokens[$i]); + $tokens[$i] =~ tr/ /0/; + } + } + } + # Pad the first digit_group if there was only one + if (1 == $digit_group_count) { + $tokens[0] .= '_000000000000000' + } + my $key = join("_", @tokens); + $key =~ s/[^\p{IsAlnum}_]//g; + + return $key; + +$func$ LANGUAGE PLPERLU; + +-- regenerate sort keys for any dewey call numbers +UPDATE asset.call_number SET id = id WHERE label_class = 2; + +COMMIT;