Permalink
Browse files

Merge pull request #225 from ctfliblime/PT16572635-sudocs-sort

[#16572635] SuDocs searching and sorting improvements
  • Loading branch information...
2 parents bd2ec69 + 52d8a5c commit bcffb85aaa1bd44191898620bc8783913161bdd5 @ctfliblime ctfliblime committed Oct 12, 2011
View
34 C4/Biblio.pm
@@ -223,17 +223,12 @@ unless you can guarantee that C<ModBiblioMarc> will be called.
sub AddBiblio {
my $record = shift;
my $frameworkcode = shift;
- my $options = @_ ? shift : undef;
NormalizeBiblioValues($record);
- my $defer_marc_save = 0;
- if (defined $options and exists $options->{'defer_marc_save'} and $options->{'defer_marc_save'}) {
- $defer_marc_save = 1;
- }
-
my ($biblionumber,$biblioitemnumber,$error);
my $dbh = C4::Context->dbh;
+
# transform the data into koha-table style data
my $olddata = TransformMarcToKoha( $dbh, $record, $frameworkcode );
($biblionumber,$error) = _koha_add_biblio( $dbh, $olddata, $frameworkcode );
@@ -246,7 +241,7 @@ sub AddBiblio {
_koha_marc_update_biblioitem_cn_sort($record, $olddata, $frameworkcode);
# now add the record
- ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save;
+ ModBiblioMarc( $record, $biblionumber, $frameworkcode );
logaction("CATALOGUING", "ADD", $biblionumber, "biblio") if C4::Context->preference("CataloguingLog");
return ( $biblionumber, $biblioitemnumber );
@@ -3324,14 +3319,23 @@ Returns undef. croak()s on failure.
sub NormalizeBiblioValues {
my $record = shift;
- for my $field ($record->field('086')) {
- my $a = $field->subfield('a');
- my $sudocs = try { Text::SuDocs->new($a) }
- catch {
- croak "Unrecognized SuDocs (086\$a) format: '$a'";
- };
- $field->update(a => $sudocs->normal_string);
- }
+ my $f086 = $record->field('086');
+ return if !$f086;
+
+ my $f086a = $f086->subfield('a');
+ return if !$f086a;
+
+ my $sudocs =
+ try { Text::SuDocs->new($f086a) }
+ catch { croak "Unrecognized SuDocs (086\$a) format: '$f086a'" };
+
+ $f086->update(a => $sudocs->normal_string);
+
+ my $f942 = $record->field('942')
+ // MARC::Field->new('942', ' ', ' ', h=>$sudocs->normal_string);
+ $record->delete_fields($f942);
+ $f942->update(2 => 'sudocs', h => $sudocs->normal_string);
+ $record->insert_fields_ordered($f942);
}
1;
View
6 C4/ClassSortRoutine.pm
@@ -99,11 +99,7 @@ sub GetClassSortKey {
$loaded_routines{$sort_routine} = \&_get_class_sort_key;
}
my $key = $loaded_routines{$sort_routine}->($cn_class, $cn_item);
- # FIXME -- hardcoded length for cn_sort
- # should replace with some way of getting column widths from
- # the DB schema -- since doing this should ideally be
- # independent of the DBMS, deferring for the moment.
- return substr($key, 0, 30);
+ return $key;
}
=head2 _get_class_sort_key
View
64 C4/ClassSortRoutine/SuDocs.pm
@@ -0,0 +1,64 @@
+package C4::ClassSortRoutine::SuDocs;
+
+# Copyright (C) 2011 PTFS, Inc.
+#
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+
+use Koha;
+use Text::SuDocs;
+
+=head1 NAME
+
+C4::ClassSortRoutine::SuDocs - SuDocs call number sorting key routine
+
+=head1 SYNOPSIS
+
+use C4::ClassSortRoutine;
+
+my $cn_sort = GetClassSortKey('SuDocs', $cn_class, $cn_item);
+
+=head1 FUNCTIONS
+
+=head2 get_class_sort_key
+
+ my $cn_sort = C4::ClassSortRoutine::SuDocs::get_class_sort_key($cn_class, $cn_item);
+
+Generates sorting key using Text::SuDocs->sortable_string.
+
+=cut
+
+sub get_class_sort_key {
+ my ($cn_class, $cn_item) = @_;
+
+ #return '' if (!defined $cn_class);
+
+ my $in = $cn_class // q{};
+ $in .= ($cn_item) ? " $cn_item" : q{};
+
+ return $in if ($in eq 'a b'); # to pacify the class loader
+
+ my $s = Text::SuDocs->new($in);
+ return $s->sortable_string();
+}
+
+1;
+
+=head1 AUTHOR
+
+LibLime/PTFS, Inc. <info@koha.org>
+
+=cut
+
View
2 C4/Context.pm
@@ -32,7 +32,7 @@ use POSIX ();
use JSON qw(from_json);
use Koha;
-$VERSION = '4.09.02.002';
+$VERSION = '4.09.02.003';
if ($ENV{'HTTP_USER_AGENT'}) {
require CGI::Carp;
View
4 C4/Search.pm
@@ -448,10 +448,10 @@ sub getRecords {
$sort_by .= "1=9003 >i ";
}
elsif ( $sort eq "call_number_asc" ) {
- $sort_by .= "1=8007 <i ";
+ $sort_by .= "1=9005 <i ";
}
elsif ( $sort eq "call_number_dsc" ) {
- $sort_by .= "1=8007 >i ";
+ $sort_by .= "1=9005 >i ";
}
elsif ( $sort eq "pubdate_asc" ) {
$sort_by .= "1=31 <i ";
View
17 catalogue/search.pl
@@ -348,12 +348,19 @@ =head3 Additional Notes
my $default_sort_by = C4::Context->preference('defaultSortField')."_".C4::Context->preference('defaultSortOrder')
if (C4::Context->preference('defaultSortField') && C4::Context->preference('defaultSortOrder'));
-@sort_by = split("\0",$params->{'sort_by'}) if $params->{'sort_by'};
-$sort_by[0] = $default_sort_by unless $sort_by[0];
-foreach my $sort (@sort_by) {
- $template->param($sort => 1);
+push @sort_by, ($params->{sort_by1} // $default_sort_by);
+$template->param(
+ 'sort_by1' => $sort_by[0],
+ "$sort_by[0]1" => 'selected="1"',
+ );
+
+if ($params->{sort_by2}) {
+ push @sort_by, $params->{sort_by2};
+ $template->param(
+ 'sort_by2' => $sort_by[1],
+ "$sort_by[1]2" => 'selected="1"',
+ );
}
-$template->param('sort_by' => $sort_by[0]);
# Use the servers defined, or just search our local catalog(default)
my @servers;
View
10 installer/data/mysql/kohastructure.sql
@@ -416,7 +416,7 @@ CREATE TABLE `biblioitems` (
`cn_class` varchar(30) default NULL,
`cn_item` varchar(10) default NULL,
`cn_suffix` varchar(10) default NULL,
- `cn_sort` varchar(30) default NULL,
+ `cn_sort` VARCHAR(128) default NULL,
`totalissues` int(10),
`on_order_count` varchar(80) default NULL,
`in_process_count` varchar(80) default NULL,
@@ -854,7 +854,7 @@ CREATE TABLE `deletedbiblioitems` (
`cn_class` varchar(30) default NULL,
`cn_item` varchar(10) default NULL,
`cn_suffix` varchar(10) default NULL,
- `cn_sort` varchar(30) default NULL,
+ `cn_sort` VARCHAR(128) default NULL,
`totalissues` int(10),
`on_order_count` varchar(80) default NULL,
`in_process_count` varchar(80) default NULL,
@@ -981,7 +981,7 @@ CREATE TABLE `deleteditems` (
`permanent_location` varchar(80) default NULL,
`onloan` date default NULL,
`cn_source` varchar(10) default NULL,
- `cn_sort` varchar(30) default NULL,
+ `cn_sort` VARCHAR(128) default NULL,
`ccode` varchar(10) default NULL,
`materials` varchar(10) default NULL,
`uri` varchar(255) default NULL,
@@ -1231,7 +1231,7 @@ CREATE TABLE `items` (
`permanent_location` varchar(80) default NULL,
`onloan` date default NULL,
`cn_source` varchar(10) default NULL,
- `cn_sort` varchar(30) default NULL,
+ `cn_sort` VARCHAR(128) default NULL,
`ccode` varchar(10) default NULL,
`materials` varchar(10) default NULL,
`uri` varchar(255) default NULL,
@@ -2523,7 +2523,7 @@ CREATE TABLE IF NOT EXISTS `subscription_defaults` (
`location` varchar(80) default NULL,
`onloan` date default NULL,
`cn_source` varchar(10) default NULL,
- `cn_sort` varchar(30) default NULL,
+ `cn_sort` VARCHAR(128) default NULL,
`ccode` varchar(10) default NULL,
`materials` varchar(10) default NULL,
`uri` varchar(255) default NULL,
View
12 installer/data/mysql/updatedatabase.pl
@@ -4778,6 +4778,18 @@
SetVersion ($DBversion);
}
+$DBversion = '4.09.02.003';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do('ALTER TABLE biblioitems MODIFY cn_sort VARCHAR(128) DEFAULT NULL');
+ $dbh->do('ALTER TABLE deletedbiblioitems MODIFY cn_sort VARCHAR(128) DEFAULT NULL');
+ $dbh->do('ALTER TABLE items MODIFY cn_sort VARCHAR(128) DEFAULT NULL');
+ $dbh->do('ALTER TABLE deleteditems MODIFY cn_sort VARCHAR(128) DEFAULT NULL');
+ $dbh->do('ALTER TABLE subscription_defaults MODIFY cn_sort VARCHAR(128) DEFAULT NULL');
+
+ SetVersion ($DBversion);
+ print "Upgrade to $DBversion done ( enlarge cn_sort )\n";
+}
+
printf "Database schema now up to date at version %s as of %s.\n", $DBversion, scalar localtime;
View
82 koha-tmpl/intranet-tmpl/prog/en/includes/resort_form.inc
@@ -1,86 +1,28 @@
<option value="relevance">Relevance</option>
-
<optgroup label="Popularity">
-
- <!-- TMPL_IF NAME="popularity_dsc" -->
-<option value="popularity_dsc" selected="selected">Popularity (Most to Least)</option>
-<!-- TMPL_ELSE -->
- <option value="popularity_dsc">Popularity (Most to Least)</option>
- <!-- /TMPL_IF -->
-<!-- TMPL_IF NAME="popularity_asc" -->
-<option value="popularity_asc" selected="selected">Popularity (Least to Most)</option>
-<!-- TMPL_ELSE -->
- <option value="popularity_asc">Popularity (Least to Most)</option>
- <!-- /TMPL_IF -->
-
+ <option value="popularity_dsc" <!-- TMPL_VAR NAME="popularity_dsc"-->>Popularity (Most to Least)</option>
+ <option value="popularity_asc" <!-- TMPL_VAR NAME="popularity_asc" -->>Popularity (Least to Most)</option>
</optgroup>
<optgroup label="Author">
-
- <!-- TMPL_IF NAME="author_az" -->
-<option value="author_az" selected="selected">Author (A-Z)</option>
-<!-- TMPL_ELSE -->
-<option value="author_az">Author (A-Z)</option>
- <!-- /TMPL_IF -->
-<!-- TMPL_IF NAME="author_za" -->
-<option value="author_za" selected="selected">Author (Z-A)</option>
-<!-- TMPL_ELSE -->
-<option value="author_za">Author (Z-A)</option>
- <!-- /TMPL_IF -->
-
+ <option value="author_az" <!-- TMPL_VAR NAME="author_az" -->>Author (A-Z)</option>
+ <option value="author_za" <!-- TMPL_VAR NAME="author_za" -->>Author (Z-A)</option>
</optgroup>
<optgroup label="Call Number">
-
- <!-- TMPL_IF NAME="call_number_asc" -->
-<option value="call_number_asc" selected="selected">Call Number (Non-fiction 0-9 to Fiction A-Z)</option>
-<!-- TMPL_ELSE -->
- <option value="call_number_asc">Call Number (Non-fiction 0-9 to Fiction A-Z)</option>
-<!-- /TMPL_IF -->
-
-<!-- TMPL_IF NAME="call_number_dsc" -->
-<option value="call_number_dsc" selected="selected">Call Number (Fiction Z-A to Non-fiction 9-0)</option>
-<!-- TMPL_ELSE -->
- <option value="call_number_dsc">Call Number (Fiction Z-A to Non-fiction 9-0)</option>
-<!-- /TMPL_IF -->
-
+ <option value="call_number_asc" <!-- TMPL_VAR NAME="call_number_asc" -->>Call Number (Ascending)</option>
+ <option value="call_number_dsc" <!-- TMPL_VAR NAME="call_number_dsc" -->>Call Number (Descending)</option>
</optgroup>
<optgroup label="Dates">
- <!-- TMPL_IF NAME="pubdate_dsc" -->
-<option value="pubdate_dsc" selected="selected" >Publication/Copyright Date: Newest to Oldest</option>
- <!-- TMPL_ELSE -->
-<option value="pubdate_dsc">Publication/Copyright Date: Newest to Oldest</option>
-<!-- /TMPL_IF -->
-
-<!-- TMPL_IF NAME="pubdate_asc" -->
-<option value="pubdate_asc" selected="selected" >Publication/Copyright Date: Oldest to Newest</option>
-<!-- TMPL_ELSE -->
-<option value="pubdate_asc">Publication/Copyright Date: Oldest to Newest</option>
-<!-- /TMPL_IF -->
-
-<!-- TMPL_IF NAME="acqdate_dsc" -->
-<option value="acqdate_dsc" selected="selected">Acquisition Date: Newest to Oldest</option>
-<!-- TMPL_ELSE -->
-<option value="acqdate_dsc">Acquisition Date: Newest to Oldest</option>
- <!-- /TMPL_IF -->
+ <option value="pubdate_dsc" <!-- TMPL_VAR NAME="pubdate_dsc" -->>Publication/Copyright Date: Newest to Oldest</option>
+ <option value="pubdate_asc" <!-- TMPL_VAR NAME="pubdate_asc" -->>Publication/Copyright Date: Oldest to Newest</option>
- <!-- TMPL_IF NAME="acqdate_asc" -->
-<option value="acqdate_asc" selected="selected">Acquisition Date: Oldest to Newest</option>
-<!-- TMPL_ELSE -->
-<option value="acqdate_asc">Acquisition Date: Oldest to Newest</option>
- <!-- /TMPL_IF -->
+ <option value="acqdate_dsc" <!-- TMPL_VAR NAME="acqdate_dsc" -->>Acquisition Date: Newest to Oldest</option>
+ <option value="acqdate_asc" <!-- TMPL_VAR NAME="acqdate_asc" -->>Acquisition Date: Oldest to Newest</option>
</optgroup>
<optgroup label="Title">
- <!-- TMPL_IF NAME="title_az" -->
-<option value="title_az" selected="selected">Title (A-Z)</option>
- <!-- TMPL_ELSE -->
-<option value="title_az">Title (A-Z)</option>
- <!-- /TMPL_IF -->
- <!-- TMPL_IF NAME="title_za" -->
-<option value="title_za" selected="selected">Title (Z-A)</option>
- <!-- TMPL_ELSE -->
-<option value="title_za">Title (Z-A)</option>
-<!-- /TMPL_IF -->
+ <option value="title_az" <!-- TMPL_VAR NAME="title_az" -->>Title (A-Z)</option>
+ <option value="title_za" <!-- TMPL_VAR NAME="title_za" -->>Title (Z-A)</option>
</optgroup>
View
28 koha-tmpl/intranet-tmpl/prog/en/includes/resort_form1.inc
@@ -0,0 +1,28 @@
+<option value="relevance">Relevance</option>
+<optgroup label="Popularity">
+ <option value="popularity_dsc" <!-- TMPL_VAR NAME="popularity_dsc1"-->>Popularity (Most to Least)</option>
+ <option value="popularity_asc" <!-- TMPL_VAR NAME="popularity_asc1" -->>Popularity (Least to Most)</option>
+</optgroup>
+
+<optgroup label="Author">
+ <option value="author_az" <!-- TMPL_VAR NAME="author_az1" -->>Author (A-Z)</option>
+ <option value="author_za" <!-- TMPL_VAR NAME="author_za1" -->>Author (Z-A)</option>
+</optgroup>
+
+<optgroup label="Call Number">
+ <option value="call_number_asc" <!-- TMPL_VAR NAME="call_number_asc1" -->>Call Number (Ascending)</option>
+ <option value="call_number_dsc" <!-- TMPL_VAR NAME="call_number_dsc1" -->>Call Number (Descending)</option>
+</optgroup>
+
+<optgroup label="Dates">
+ <option value="pubdate_dsc" <!-- TMPL_VAR NAME="pubdate_dsc1" -->>Publication/Copyright Date: Newest to Oldest</option>
+ <option value="pubdate_asc" <!-- TMPL_VAR NAME="pubdate_asc1" -->>Publication/Copyright Date: Oldest to Newest</option>
+
+ <option value="acqdate_dsc" <!-- TMPL_VAR NAME="acqdate_dsc1" -->>Acquisition Date: Newest to Oldest</option>
+ <option value="acqdate_asc" <!-- TMPL_VAR NAME="acqdate_asc1" -->>Acquisition Date: Oldest to Newest</option>
+</optgroup>
+
+<optgroup label="Title">
+ <option value="title_az" <!-- TMPL_VAR NAME="title_az1" -->>Title (A-Z)</option>
+ <option value="title_za" <!-- TMPL_VAR NAME="title_za1" -->>Title (Z-A)</option>
+</optgroup>
View
28 koha-tmpl/intranet-tmpl/prog/en/includes/resort_form2.inc
@@ -0,0 +1,28 @@
+<option value="relevance">Relevance</option>
+<optgroup label="Popularity">
+ <option value="popularity_dsc" <!-- TMPL_VAR NAME="popularity_dsc2"-->>Popularity (Most to Least)</option>
+ <option value="popularity_asc" <!-- TMPL_VAR NAME="popularity_asc2" -->>Popularity (Least to Most)</option>
+</optgroup>
+
+<optgroup label="Author">
+ <option value="author_az" <!-- TMPL_VAR NAME="author_az2" -->>Author (A-Z)</option>
+ <option value="author_za" <!-- TMPL_VAR NAME="author_za2" -->>Author (Z-A)</option>
+</optgroup>
+
+<optgroup label="Call Number">
+ <option value="call_number_asc" <!-- TMPL_VAR NAME="call_number_asc2" -->>Call Number (Ascending)</option>
+ <option value="call_number_dsc" <!-- TMPL_VAR NAME="call_number_dsc2" -->>Call Number (Descending)</option>
+</optgroup>
+
+<optgroup label="Dates">
+ <option value="pubdate_dsc" <!-- TMPL_VAR NAME="pubdate_dsc2" -->>Publication/Copyright Date: Newest to Oldest</option>
+ <option value="pubdate_asc" <!-- TMPL_VAR NAME="pubdate_asc2" -->>Publication/Copyright Date: Oldest to Newest</option>
+
+ <option value="acqdate_dsc" <!-- TMPL_VAR NAME="acqdate_dsc2" -->>Acquisition Date: Newest to Oldest</option>
+ <option value="acqdate_asc" <!-- TMPL_VAR NAME="acqdate_asc2" -->>Acquisition Date: Oldest to Newest</option>
+</optgroup>
+
+<optgroup label="Title">
+ <option value="title_az" <!-- TMPL_VAR NAME="title_az2" -->>Title (A-Z)</option>
+ <option value="title_za" <!-- TMPL_VAR NAME="title_za2" -->>Title (Z-A)</option>
+</optgroup>
View
17 koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tmpl
@@ -30,7 +30,10 @@ var q_array = new Array(); // will hold search terms, if present
$(document).ready(function() {
$('#sortbyform').find("input:submit").hide();
- $('#sort_by').change(function() {
+ $('#sort_by1').change(function() {
+ $('#sortbyform').submit();
+ });
+ $('#sort_by2').change(function() {
$('#sortbyform').submit();
});
$("#selection_ops").show();
@@ -172,10 +175,14 @@ function GetZ3950Terms(){
<!-- /TMPL_LOOP -->
<!-- /TMPL_IF -->
<!-- RE-SORT START -->
- <label for="sort_by">Sort By: </label>
- <select id="sort_by" name="sort_by">
- <!-- TMPL_INCLUDE NAME="resort_form.inc" -->
- </select>
+ <label for="sort_by1">Sort By (primary): </label>
+ <select id="sort_by1" name="sort_by1">
+ <!-- TMPL_INCLUDE NAME="resort_form1.inc" -->
+ </select><br/>
+ <label for="sort_by2">Sort By (secondary): </label>
+ <select id="sort_by2" name="sort_by2">
+ <!-- TMPL_INCLUDE NAME="resort_form2.inc" -->
+ </select><br/>
<input type="submit" value="Go" />
<!-- RESORT END -->
</form>
View
2 kohaversion.pl
@@ -10,7 +10,7 @@
use strict;
sub kohaversion {
- our $VERSION = '4.09.02.002';
+ our $VERSION = '4.09.02.003';
# version needs to be set this way
# so that it can be picked up by Makefile.PL
# during install
View
59 misc/make_sudocs_searchable.pl
@@ -0,0 +1,59 @@
+#!/usr/bin/env perl
+
+use Koha;
+use Data::Dumper;
+
+use C4::Context;
+use C4::Biblio;
+use C4::Items;
+
+use MARC::Record;
+use MARC::Field;
+use Try::Tiny;
+use Carp;
+
+sub normalize_cn {
+ my $biblionumber = shift;
+ my (undef, $biblio) = GetBiblio($biblionumber);
+ my $record = GetMarcBiblio($biblionumber);
+ my $f086 = $record->field('086');
+ return if !$f086;
+
+ my $s = try {
+ Text::SuDocs->new($record->subfield('086', 'a'))
+ }
+ catch {
+ carp sprintf('Unparseable SuDocs (%s):%s', $record->subfield('086', 'a'), $_);
+ undef;
+ };
+ return if !$s;
+ $s = undef;
+
+ my $f942 = $record->field(942);
+ if ($f942) {
+ $record->delete_fields($f942);
+ }
+ else {
+ $f942 = MARC::Field->new('942', ' ', ' ', a=>123);
+ }
+
+ $f942->update(2 => 'sudocs',
+ h => $record->subfield('086', 'a'));
+ $record->insert_fields_ordered($f942);
+
+ try {
+ ModBiblio($record, $biblionumber, $biblio->{frameworkcode});
+ }
+ catch {
+ carp "Unable to update $biblionumber: $_";
+ };
+}
+
+my $biblionumbers = [qw(2087 2088 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660)];
+
+$biblionumbers = C4::Context->dbh->selectcol_arrayref('SELECT biblionumber FROM biblio');
+
+for (@$biblionumbers) {
+ say $_;
+ normalize_cn($_);
+}

0 comments on commit bcffb85

Please sign in to comment.