From 09ebb27d8c50cf8ddf490211800f6a35db8f5f50 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 21 Jan 2014 08:55:30 -0500 Subject: [PATCH] LP#1053397 MR search and results display Signed-off-by: Bill Erickson --- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm | 22 +++++++++--- .../perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm | 42 ++++++++++++++-------- .../src/templates/opac/parts/advanced/search.tt2 | 13 ++++++- Open-ILS/src/templates/opac/parts/result/table.tt2 | 29 ++++++++++++--- 4 files changed, 81 insertions(+), 25 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm index 1a8740c206..cadc189fff 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm @@ -67,7 +67,8 @@ sub _prepare_biblio_search { foreach ($cgi->param('modifier')) { # The unless bit is to avoid stacking modifiers. - $query = ('#' . $_ . ' ' . $query) unless $query =~ qr/\#\Q$_/; + $query = ('#' . $_ . ' ' . $query) unless + $query =~ qr/\#\Q$_/ or $_ eq 'metabib'; } # filters @@ -307,6 +308,10 @@ sub load_rresults { my $ctx = $self->ctx; my $e = $self->editor; + my @mods = $cgi->param('modifier'); + my $is_meta = @mods and grep { $_ eq 'metabib' } @mods; + my $id_key = $is_meta ? 'mmr_id' : 'bre_id'; + # find the last record in the set, then redirect my $find_last = $cgi->param('find_last'); @@ -316,7 +321,9 @@ sub load_rresults { return $bbag_err; } - $ctx->{page} = 'rresult' unless $internal; + if (!$internal) { + $ctx->{page} = $is_meta ? 'mresult' : 'rresult'; + } $ctx->{ids} = []; $ctx->{records} = []; $ctx->{search_facets} = {}; @@ -411,12 +418,14 @@ sub load_rresults { $query = "$_ $query" for @facets; - $logger->activity("EGWeb: [search] $query"); + my $ltag = $is_meta ? '[mmr search]' : '[bre search]'; + $logger->activity("EGWeb: $ltag $query"); try { my $method = 'open-ils.search.biblio.multiclass.query'; $method .= '.staff' if $ctx->{is_staff}; + $method =~ s/biblio/metabib/ if $is_meta; my $ses = OpenSRF::AppSession->create('open-ils.search'); @@ -443,6 +452,7 @@ sub load_rresults { my $rec_id = pop @$rec_ids; $cgi->delete('find_last'); my $url = $cgi->url(-full => 1, -path => 1, -query => 1); + # TODO: metarecord => /rresults?metarecord=$mmr_id $url =~ s|/results|/record/$rec_id|; return $self->generic_redirect($url); } @@ -457,6 +467,7 @@ sub load_rresults { { flesh => '{holdings_xml,mra,acp,acnp,acns,bmp}', site => $site, + metarecord => $is_meta, depth => $depth, pref_lib => $ctx->{pref_ou}, } @@ -464,6 +475,7 @@ sub load_rresults { $self->timelog("Returned from get_records_and_facets()"); if ($page == 0) { + # TODO: handle metarecords my $stat = $self->check_1hit_redirect($rec_ids); return $stat if $stat; } @@ -475,13 +487,13 @@ sub load_rresults { for my $rec_id (@$rec_ids) { push( @{$ctx->{records}}, - grep { $_->{id} == $rec_id } @data + grep { $_->{$id_key} == $rec_id } @data ); } if ($tag_circs) { for my $rec (@{$ctx->{records}}) { - my ($res_rec) = grep { $_->[0] == $rec->{id} } @{$results->{ids}}; + my ($res_rec) = grep { $_->[0] == $rec->{$id_key} } @{$results->{ids}}; # index 1 in the per-record result array is a boolean which # indicates whether the record in question is in the users # accessible circ history list diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm index db2ad9aba0..c4e14cf052 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -307,34 +307,45 @@ sub get_records_and_facets { my $xml = XML::LibXML->new->parse_string($data->{$unapi_type})->documentElement; - # NOTE: in metarecord mode, the bre_id will be that of the master - # record, in which case the bre_id acts as a secondary identifier - # for the metarecord. Caching via $bre_id (w/ is_meta key_suffix - # adjustments from above) should still produce unique cache - # values for each MR. IOW, there' no particular need to extract - # the MR id. - $outer_self->timelog("get_records_and_facets(): parsed xml"); # Protect against legacy invalid MARCXML that might not have a 901c my $bre_id; + my $mmr_id; my $bre_id_nodes = $xml->find('*[@tag="901"]/*[@code="c"]'); if ($bre_id_nodes) { $bre_id = $bre_id_nodes->[0]->textContent; } else { $logger->warn("Missing 901 subfield 'c' in " . $xml->toString()); } - $tmp_data{$bre_id} = {id => $bre_id, marc_xml => $xml}; - if ($bre_id) { + if ($is_meta) { + # extract metarecord ID from mmr.unapi tag + for my $node ($xml->getElementsByTagName('abbr')) { + my $title = $node->getAttribute('title'); + ($mmr_id = $title) =~ + s/tag:open-ils.org:U2\@mmr\/(\d+)\/.*/$1/g; + last if $mmr_id; + } + } + + my $rec_id = $mmr_id ? $mmr_id : $bre_id; + $tmp_data{$bre_id} = { + id => $rec_id, # for backwards compat + bre_id => $bre_id, + mmr_id => $mmr_id, + marc_xml => $xml + }; + + if ($rec_id) { # Let other backends grab our data now that we're done. - my $key = 'TPAC_unapi_cache_'.$bre_id.'_'.$unapi_cache_key_suffix; + my $key = 'TPAC_unapi_cache_'.$rec_id.'_'.$unapi_cache_key_suffix; my $cache_data = $unapi_cache->get_cache($key); if ($$cache_data{running}) { - $unapi_cache->put_cache($key, { id => $bre_id, marc_xml => $data->{$unapi_type} }, 10); + $unapi_cache->put_cache($key, + {id => $rec_id, marc_xml => $data->{$unapi_type} }, 10); } } - $outer_self->timelog("get_records_and_facets(): end of success handler"); } ); @@ -375,12 +386,15 @@ sub get_records_and_facets { my $sdepth = $unapi_args->{flesh_depth}; my $slimit = "acn=>$sdepth,acp=>$sdepth"; $slimit .= ",bre=>$sdepth" if $is_meta; + my $flesh = $unapi_args->{flesh} || ''; + + # tag the record with the MR id + $flesh =~ s/}$/,mmr.unapi}/g if $is_meta; $ses->request( 'open-ils.cstore.json_query', {from => [ - $unapi_type, $bid, 'marcxml','record', - $unapi_args->{flesh}, + $unapi_type, $bid, 'marcxml','record', $flesh, $unapi_args->{site}, $unapi_args->{depth}, $slimit, diff --git a/Open-ILS/src/templates/opac/parts/advanced/search.tt2 b/Open-ILS/src/templates/opac/parts/advanced/search.tt2 index 42e5cfcebd..1fbd037f93 100644 --- a/Open-ILS/src/templates/opac/parts/advanced/search.tt2 +++ b/Open-ILS/src/templates/opac/parts/advanced/search.tt2 @@ -98,8 +98,19 @@ CASE "sort_selector"; INCLUDE "opac/parts/filtersort.tt2" value=CGI.param('sort') class='results_header_sel'; + %] - CASE "copy_location" %] + +
+ + +
+ + [% CASE "copy_location" %]