From 11cb238f4f5f9e0bf85f3d2296ffa77c5fbf02f9 Mon Sep 17 00:00:00 2001 From: Thomas Berezansky Date: Tue, 12 Jun 2012 13:42:10 -0400 Subject: [PATCH] Expose sortable title in mvr Signed-off-by: Thomas Berezansky --- Open-ILS/examples/fm_IDL.xml | 1 + .../src/perlmods/lib/OpenILS/Application/Actor.pm | 1 + .../src/perlmods/lib/OpenILS/Utils/ModsParser.pm | 23 ++++++++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index c161085bbd..fa59326437 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -66,6 +66,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm index 5f6073fa4b..d341929018 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm @@ -1891,6 +1891,7 @@ sub flesh_circ { $mods = new Fieldmapper::metabib::virtual_record; $mods->doc_id(OILS_PRECAT_RECORD); $mods->title($copy->dummy_title); + $mods->titlesort($copy->dummy_title); $mods->author($copy->dummy_author); } else { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Utils/ModsParser.pm b/Open-ILS/src/perlmods/lib/OpenILS/Utils/ModsParser.pm index 1ab2c86a48..4d943b2f8f 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Utils/ModsParser.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Utils/ModsParser.pm @@ -42,6 +42,8 @@ my $xpathset = { "//mods:mods/mods:titleInfo[mods:title and (\@type='uniform')]", proper => "//mods:mods/mods:titleInfo[mods:title and not (\@type)]", + sortkey => + "//mods:mods/mods:titleInfo[mods:title and not (\@type)]", any => "//mods:mods/mods:titleInfo", }, @@ -110,7 +112,7 @@ sub new { return bless( {}, shift() ); } sub get_field_value { - my( $self, $mods, $xpath, $type) = @_; + my( $self, $mods, $xpath, $class, $type) = @_; my @string; @@ -126,10 +128,13 @@ sub get_field_value { my @children = $value->childNodes(); my @child_text; for my $child (@children) { + # Magic for title-sorting special value, skip the nonSort node + next if ($class && $class eq 'title' && $type && $type eq 'sortkey' && $child->nodeName =~ m/nonSort/); + # MODS strips the punctuation from 245abc, which often # results in "title subtitle" rather than "title : subtitle"; # this hack gets it back for us - if ($type && $type eq 'title' && $child->nodeName =~ m/subTitle/) { + if ($class && $class eq 'title' && $child->nodeName =~ m/subTitle/) { push(@child_text, " : "); } next unless( $child->nodeType != 3 ); @@ -202,7 +207,7 @@ sub modsdoc_to_values { my $class = "title"; $data->{$class} = {}; for my $type(keys %{$xpathset->{$class}}) { - my @value = $self->get_field_value( $mods, $xpathset->{$class}->{$type}, "title" ); + my @value = $self->get_field_value( $mods, $xpathset->{$class}->{$type}, "title", $type ); for my $arr (@value) { if( ref($arr) ) { $data->{$class}->{$type} = shift @$arr; @@ -263,6 +268,7 @@ sub mods_values_to_mods_slim { my( $self, $modsperl ) = @_; my $title = ""; + my $titlesort = ""; my $author = ""; my $subject = []; my $series = []; @@ -279,6 +285,13 @@ sub mods_values_to_mods_slim { ($title = $tmp->{any}); } + # Just another title value check, so we can re-use the previous tmp lookup + if(!$tmp) { $titlesort = ""; } + else { + ($titlesort = $tmp->{sortkey}) || + ($titlesort = $title); + } + $tmp = $modsperl->{author}; if(!$tmp) { $author = ""; } else { @@ -307,7 +320,7 @@ sub mods_values_to_mods_slim { else { $series = $tmp->{'series'}; } - return { series => $series, title => $title, + return { series => $series, title => $title, titlesort => $titlesort, author => $author, subject => $subject }; } @@ -440,6 +453,7 @@ sub finish_mods_batch { #(my $title = $perl->{title}) =~ s/\[.*?\]//og; #(my $author = $perl->{author}) =~ s/\(.*?\)//og; my $title = $perl->{title}; + my $titlesort = $perl->{titlesort}; my $author = $perl->{author}; my @series; @@ -453,6 +467,7 @@ sub finish_mods_batch { $rtypes = [ keys %hash ]; $record->title($title); + $record->titlesort($titlesort); $record->author($author); $record->doc_id($perl->{doc_id}); -- 2.11.0