Expose sortable title in mvr
authorThomas Berezansky <tsbere@mvlc.org>
Tue, 12 Jun 2012 17:42:10 +0000 (13:42 -0400)
committerJason Stephenson <jason@sigio.com>
Wed, 30 Jan 2013 20:14:31 +0000 (15:14 -0500)
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>
Open-ILS/examples/fm_IDL.xml
Open-ILS/src/perlmods/lib/OpenILS/Application/Actor.pm
Open-ILS/src/perlmods/lib/OpenILS/Utils/ModsParser.pm

index c161085..fa59326 100644 (file)
@@ -66,6 +66,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
        <class id="mvr" controller="open-ils.cstore" oils_obj:fieldmapper="metabib::virtual_record" oils_persist:virtual="true" reporter:label="Virtual Record">
                <fields>
                        <field name="title" oils_persist:virtual="true" />
+                       <field name="titlesort" oils_persist:virtual="true" />
                        <field name="author" oils_persist:virtual="true" />
                        <field name="doc_id" oils_persist:virtual="true" />
                        <field name="doc_type" oils_persist:virtual="true" />
index 5f6073f..d341929 100644 (file)
@@ -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 {
index 1ab2c86..4d943b2 100644 (file)
@@ -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});