From ef6d210d2e770680c4becf681dcfd6ad9635f907 Mon Sep 17 00:00:00 2001 From: gmc Date: Thu, 21 Oct 2010 14:44:35 +0000 Subject: [PATCH] improve call number sorting oils_text_as_bytea now does uppercasing in addition to converting strings to bytea, working around the limitation that json_query can't stack transforms Signed-off-by: Galen Charlton git-svn-id: svn://svn.open-ils.org/ILS/trunk@18434 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../OpenILS/Application/Storage/Publisher/asset.pm | 16 ++++++++-------- Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm | 16 ++++++++-------- Open-ILS/src/sql/Pg/002.functions.config.sql | 2 +- Open-ILS/src/sql/Pg/002.schema.config.sql | 2 +- Open-ILS/src/sql/Pg/040.schema.asset.sql | 2 +- Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm index 77b213da20..e227981880 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/asset.pm @@ -230,9 +230,9 @@ sub cn_browse_pagedown { $table cn where not deleted - and (oils_text_as_bytea(upper(label)) > ? or ( cn.id > ? and oils_text_as_bytea(upper(label)) = ? )) + and (oils_text_as_bytea(label) > ? or ( cn.id > ? and oils_text_as_bytea(label) = ? )) and owning_lib in ($orgs) - order by oils_text_as_bytea(upper(label)), 4, 2 + order by oils_text_as_bytea(label), 4, 2 limit $size; SQL @@ -285,9 +285,9 @@ sub cn_browse_pageup { $table cn where not deleted - and (oils_text_as_bytea(upper(label)) < ? or ( cn.id < ? and oils_text_as_bytea(upper(label)) = ? )) + and (oils_text_as_bytea(label) < ? or ( cn.id < ? and oils_text_as_bytea(label) = ? )) and owning_lib in ($orgs) - order by oils_text_as_bytea(upper(label)) desc, 4 desc, 2 desc + order by oils_text_as_bytea(label) desc, 4 desc, 2 desc limit $size ) as bar order by 1,4,2; @@ -343,9 +343,9 @@ sub cn_browse_target { $table cn where not deleted - and oils_text_as_bytea(upper(label)) < ? + and oils_text_as_bytea(label) < ? and owning_lib in ($orgs) - order by oils_text_as_bytea(upper(label)) desc, 4 desc, 2 desc + order by oils_text_as_bytea(label) desc, 4 desc, 2 desc limit $topsize ) as bar order by 1,4,2; @@ -361,9 +361,9 @@ sub cn_browse_target { $table cn where not deleted - and oils_text_as_bytea(upper(label)) >= ? + and oils_text_as_bytea(label) >= ? and owning_lib in ($orgs) - order by oils_text_as_bytea(upper(label)),4,2 + order by oils_text_as_bytea(label),4,2 limit $bottomsize; SQL diff --git a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm index 714e676fec..fbc412ef61 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/SuperCat.pm @@ -298,14 +298,14 @@ sub cn_browse { if ($page <= 0) { my $before = $_storage->request( "open-ils.cstore.direct.asset.call_number.search.atomic", - { label => { "<" => { transform => "upper", value => ["upper", $label] } }, + { label => { "<" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label] } }, owning_lib => \@ou_ids, deleted => 'f', @cp_filter }, { flesh => 1, flesh_fields => { acn => [qw/record owning_lib/] }, - order_by => { acn => "oils_text_as_bytea(label_sortkey) desc, oils_text_as_bytea(upper(label)) desc, id desc, owning_lib desc" }, + order_by => { acn => "oils_text_as_bytea(label_sortkey) desc, oils_text_as_bytea(label) desc, id desc, owning_lib desc" }, limit => $before_limit, offset => abs($page) * $page_size - $before_offset, } @@ -316,14 +316,14 @@ sub cn_browse { if ($page >= 0) { my $after = $_storage->request( "open-ils.cstore.direct.asset.call_number.search.atomic", - { label => { ">=" => { transform => "upper", value => ["upper", $label] } }, + { label => { ">=" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label] } }, owning_lib => \@ou_ids, deleted => 'f', @cp_filter }, { flesh => 1, flesh_fields => { acn => [qw/record owning_lib/] }, - order_by => { acn => "oils_text_as_bytea(label_sortkey), oils_text_as_bytea(upper(label)), id, owning_lib" }, + order_by => { acn => "oils_text_as_bytea(label_sortkey), oils_text_as_bytea(label), id, owning_lib" }, limit => $after_limit, offset => abs($page) * $page_size - $after_offset, } @@ -421,14 +421,14 @@ sub cn_startwith { if ($page < 0) { my $before = $_storage->request( "open-ils.cstore.direct.asset.call_number.search.atomic", - { label => { "<" => { transform => "upper", value => ["upper", $label] } }, + { label => { "<" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label] } }, owning_lib => \@ou_ids, deleted => 'f', @cp_filter }, { flesh => 1, flesh_fields => { acn => [qw/record owning_lib/] }, - order_by => { acn => "oils_text_as_bytea(label_sortkey) desc, oils_text_as_bytea(upper(label)) desc, id desc, owning_lib desc" }, + order_by => { acn => "oils_text_as_bytea(label_sortkey) desc, oils_text_as_bytea(label) desc, id desc, owning_lib desc" }, limit => $limit, offset => $offset, } @@ -439,14 +439,14 @@ sub cn_startwith { if ($page >= 0) { my $after = $_storage->request( "open-ils.cstore.direct.asset.call_number.search.atomic", - { label => { ">=" => { transform => "upper", value => ["upper", $label] } }, + { label => { ">=" => { transform => "oils_text_as_bytea", value => ["oils_text_as_bytea", $label] } }, owning_lib => \@ou_ids, deleted => 'f', @cp_filter }, { flesh => 1, flesh_fields => { acn => [qw/record owning_lib/] }, - order_by => { acn => "oils_text_as_bytea(label_sortkey), oils_text_as_bytea(upper(label)), id, owning_lib" }, + order_by => { acn => "oils_text_as_bytea(label_sortkey), oils_text_as_bytea(label), id, owning_lib" }, limit => $limit, offset => $offset, } diff --git a/Open-ILS/src/sql/Pg/002.functions.config.sql b/Open-ILS/src/sql/Pg/002.functions.config.sql index cc97d92f42..615f06b6f2 100644 --- a/Open-ILS/src/sql/Pg/002.functions.config.sql +++ b/Open-ILS/src/sql/Pg/002.functions.config.sql @@ -598,7 +598,7 @@ return; $func$ LANGUAGE PLPERLU; CREATE OR REPLACE FUNCTION oils_text_as_bytea (TEXT) RETURNS BYTEA AS $_$ - SELECT CAST(REGEXP_REPLACE($1, $$\\$$, $$\\\\$$, 'g') AS BYTEA); + SELECT CAST(REGEXP_REPLACE(UPPER($1), $$\\$$, $$\\\\$$, 'g') AS BYTEA); $_$ LANGUAGE SQL IMMUTABLE; COMMIT; diff --git a/Open-ILS/src/sql/Pg/002.schema.config.sql b/Open-ILS/src/sql/Pg/002.schema.config.sql index 24094f3681..51488080ff 100644 --- a/Open-ILS/src/sql/Pg/002.schema.config.sql +++ b/Open-ILS/src/sql/Pg/002.schema.config.sql @@ -70,7 +70,7 @@ CREATE TABLE config.upgrade_log ( install_date TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() ); -INSERT INTO config.upgrade_log (version) VALUES ('0443'); -- dbs +INSERT INTO config.upgrade_log (version) VALUES ('0444'); -- gmc 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 6b604df2a9..767f46e9ed 100644 --- a/Open-ILS/src/sql/Pg/040.schema.asset.sql +++ b/Open-ILS/src/sql/Pg/040.schema.asset.sql @@ -293,7 +293,7 @@ CREATE INDEX asset_call_number_record_idx ON asset.call_number (record); CREATE INDEX asset_call_number_creator_idx ON asset.call_number (creator); CREATE INDEX asset_call_number_editor_idx ON asset.call_number (editor); CREATE INDEX asset_call_number_dewey_idx ON asset.call_number (public.call_number_dewey(label)); -CREATE INDEX asset_call_number_upper_label_id_owning_lib_idx ON asset.call_number (oils_text_as_bytea(upper(label)),id,owning_lib); +CREATE INDEX asset_call_number_upper_label_id_owning_lib_idx ON asset.call_number (oils_text_as_bytea(label),id,owning_lib); CREATE INDEX asset_call_number_label_sortkey ON asset.call_number(oils_text_as_bytea(label_sortkey)); CREATE UNIQUE INDEX asset_call_number_label_once_per_lib ON asset.call_number (record, owning_lib, label) WHERE deleted = FALSE OR deleted IS FALSE; CREATE RULE protect_cn_delete AS ON DELETE TO asset.call_number DO INSTEAD UPDATE asset.call_number SET deleted = TRUE WHERE OLD.id = asset.call_number.id; diff --git a/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql b/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql index 94c703f3cf..231fb0543e 100644 --- a/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql +++ b/Open-ILS/src/sql/Pg/1.6.1-2.0-upgrade-db.sql @@ -2,7 +2,7 @@ -- may or may not exist. DROP INDEX asset.asset_call_number_upper_label_id_owning_lib_idx; -CREATE INDEX asset_call_number_upper_label_id_owning_lib_idx ON asset.call_number (oils_text_as_bytea(upper(label)),id,owning_lib); +CREATE INDEX asset_call_number_upper_label_id_owning_lib_idx ON asset.call_number (oils_text_as_bytea(label),id,owning_lib); \qecho Before starting the transaction: drop some constraints. -- 2.11.0