From: Jason Etheridge Date: Thu, 7 Mar 2013 16:59:09 +0000 (-0500) Subject: LP#1150939 fix dewey sort X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2dbcf19619a090cb7f07f97c586c040dd4fa9656;p=working%2FEvergreen.git LP#1150939 fix dewey sort There's a bit in the code where it tries to pad the first digit group, if it's the only digit group, but it assumed the digit group was the first token. Signed-off-by: Jason Etheridge --- diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index d773eb16b0..eb98b3d5d3 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -90,7 +90,7 @@ CREATE TRIGGER no_overlapping_deps BEFORE INSERT OR UPDATE ON config.db_patch_dependencies FOR EACH ROW EXECUTE PROCEDURE evergreen.array_overlap_check ('deprecates'); -INSERT INTO config.upgrade_log (version, applied_to) VALUES ('0764', :eg_version); -- gmcharlt/berick/bshum +INSERT INTO config.upgrade_log (version, applied_to) VALUES ('XXXX', :eg_version); -- phasefx CREATE TABLE config.bib_source ( id SERIAL PRIMARY KEY, diff --git a/Open-ILS/src/sql/Pg/040.schema.asset.sql b/Open-ILS/src/sql/Pg/040.schema.asset.sql index 541cff5bb5..17f8c5d16f 100644 --- a/Open-ILS/src/sql/Pg/040.schema.asset.sql +++ b/Open-ILS/src/sql/Pg/040.schema.asset.sql @@ -339,9 +339,13 @@ CREATE OR REPLACE FUNCTION asset.label_normalizer_dewey(TEXT) RETURNS TEXT AS $f $init =~ s/^([\p{IsAlpha}]+)/$1 /; my @tokens = split /\.|\s+/, $init; my $digit_group_count = 0; + my $first_digit_group_idx; for (my $i = 0; $i <= $#tokens; $i++) { if ($tokens[$i] =~ /^\d+$/) { $digit_group_count++; + if ($digit_group_count == 1) { + $first_digit_group_idx = $i; + } if (2 == $digit_group_count) { $tokens[$i] = sprintf("%-15.15s", $tokens[$i]); $tokens[$i] =~ tr/ /0/; @@ -350,7 +354,7 @@ 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' + $tokens[$first_digit_group_idx] .= '_000000000000000' } my $key = join("_", @tokens); $key =~ s/[^\p{IsAlnum}_]//g; @@ -359,6 +363,7 @@ CREATE OR REPLACE FUNCTION asset.label_normalizer_dewey(TEXT) RETURNS TEXT AS $f $func$ LANGUAGE PLPERLU; + CREATE OR REPLACE FUNCTION asset.label_normalizer_lc(TEXT) RETURNS TEXT AS $func$ use strict; use warnings; diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acn_dewey_normalizer.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acn_dewey_normalizer.sql new file mode 100644 index 0000000000..fa4d5015f3 --- /dev/null +++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.acn_dewey_normalizer.sql @@ -0,0 +1,52 @@ +-- Evergreen DB patch XXXX.schema.acn_dewey_normalizer.sql +-- +-- Fixes Dewey call number sorting (per LP# 1150939) +-- +BEGIN; + +-- check whether patch can be applied +SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version); + +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; + my $first_digit_group_idx; + for (my $i = 0; $i <= $#tokens; $i++) { + if ($tokens[$i] =~ /^\d+$/) { + $digit_group_count++; + if ($digit_group_count == 1) { + $first_digit_group_idx = $i; + } + 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[$first_digit_group_idx] .= '_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;