deleted => 'f',
@$cp_filter
},
- { limit => 1,
+ { flesh => 1,
+ flesh_fields => { acn => [qw/label_class/] },
+ limit => 1,
order_by => { acn => "oils_text_as_bytea(label), id" }
}
)->gather(1);
if (@$closest_cn) {
- return $closest_cn->[0]->label_sortkey;
- } else {
- return '~~~'; #fallback to high ascii value, we are at the end
+ if ($closest_cn->[0]->label eq $label) {
+ # we found an exact match stop here
+ return $closest_cn->[0]->label_sortkey;
+ } else {
+ # we got as close as we could by label alone, let's try to
+ # normalize and get closer
+ $closest_cn = $_storage->request(
+ "open-ils.cstore.direct.asset.call_number.search.atomic",
+ { label_sortkey
+ => { ">=" => [$closest_cn->[0]->label_class->normalizer, $label] },
+ owning_lib => $ou_ids,
+ deleted => 'f',
+ @$cp_filter
+ },
+ { limit => 1,
+ order_by => { acn => "label_sortkey, id" }
+ }
+ )->gather(1);
+ if (@$closest_cn) {
+ return $closest_cn->[0]->label_sortkey;
+ }
+ }
}
+
+ return '~~~'; #fallback to high ascii value, we are at the end of the range
}
sub cn_browse {
$callnum =~ s/ {2,}/ /g;
return $callnum;
-$func$ LANGUAGE PLPERLU;
+$func$ LANGUAGE PLPERLU IMMUTABLE;
CREATE OR REPLACE FUNCTION asset.label_normalizer_dewey(TEXT) RETURNS TEXT AS $func$
# Derived from the Koha C4::ClassSortRoutine::Dewey module
return $key;
-$func$ LANGUAGE PLPERLU;
+$func$ LANGUAGE PLPERLU IMMUTABLE;
CREATE OR REPLACE FUNCTION asset.label_normalizer_lc(TEXT) RETURNS TEXT AS $func$
my $callnum = Library::CallNumber::LC->new(shift);
return $callnum->normalize();
-$func$ LANGUAGE PLPERLU;
+$func$ LANGUAGE PLPERLU IMMUTABLE;
INSERT INTO asset.call_number_class (name, normalizer, field) VALUES
('Generic', 'asset.label_normalizer_generic', '050ab,055ab,060ab,070ab,080ab,082ab,086ab,088ab,090,092,096,098,099'),
--- /dev/null
+BEGIN;
+
+--SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+ALTER FUNCTION asset.label_normalizer_generic(TEXT) IMMUTABLE;
+ALTER FUNCTION asset.label_normalizer_dewey(TEXT) IMMUTABLE;
+ALTER FUNCTION asset.label_normalizer_lc(TEXT) IMMUTABLE;
+
+COMMIT;