From: Lebbeous Fogle-Weekley Date: Thu, 2 May 2013 22:44:25 +0000 (-0400) Subject: initial code not yet work for authorities 'see also' type stuff X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=24640e299797b291db7c58c25a24bc25ea26eb68;p=evergreen%2Fequinox.git initial code not yet work for authorities 'see also' type stuff has_browse_entry() refined as well Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml index ccc7117f63..a76a1740a3 100644 --- a/Open-ILS/examples/fm_IDL.xml +++ b/Open-ILS/examples/fm_IDL.xml @@ -5679,6 +5679,19 @@ SELECT usr, + + + + + + + + + + + + + diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm index 97d140f459..27f0ff5b78 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Driver/Pg/QueryParser.pm @@ -1112,8 +1112,10 @@ sub flatten { } } elsif ($filter->name eq 'has_browse_entry') { - if (@{$filter->args} > 0) { - $from .= "\n" . $spc x 3 . sprintf("INNER JOIN metabib.browse_entry_def_map mbedm ON (mbedm.source = m.source AND mbedm.entry = %d)", $filter->args->[0]); + if (@{$filter->args} >= 2) { + my $entry = int(shift @{$filter->args}); + my $fields = join(",", map(int, @{$filter->args})); + $from .= "\n" . $spc x 3 . sprintf("INNER JOIN metabib.browse_entry_def_map mbedm ON (mbedm.source = m.source AND mbedm.entry = %d AND mbedm.def IN (%s))", $entry, $fields); } } elsif ($filter->name eq 'edit_date' or $filter->name eq 'create_date') { # bre.create_date and bre.edit_date filtering diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm index af129b1b11..423903c969 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Browse.pm @@ -13,6 +13,7 @@ use OpenSRF::Utils::SettingsClient; use Digest::MD5 qw/md5_hex/; use Apache2::Const -compile => qw/OK/; +use MARC::Record; use Data::Dumper; $Data::Dumper::Indent = 0; @@ -64,23 +65,70 @@ sub prepare_browse_parameters { ); } -# This changes $results and returns 1 for success, undef for failure. -# $results must be an arrayref of result rows from the DB's metabib.browse(). +# flesh_browse_results() attaches data from authority records. It +# changes $results and returns 1 for success, undef for failure (in which +# case $self->editor->event should always point to the reason for failure). +# $results must be an arrayref of result rows from the DB's metabib.browse() sub flesh_browse_results { my ($self, $results) = @_; - my @auth_ids = map { split /,/, $_->{authorities} } @$results; + # Turn all comma-seprated strings of numbers into array. + $_->{authorities} = [split /,/, $_->{authorities}] foreach @$results; + # Group them in one arrray, not worrying about dupes because IN () takes + # care of that. + my @auth_ids = map { @{$_->{authorities}} } @$results; + + open FH, ">/tmp/lfw-auth-" . time() or die "LFW XXX $!"; + print FH Dumper(\@auth_ids), "\n"; + print FH Dumper($results), "\n"; if (@auth_ids) { - # select ash.* - # from authority.record_entry are - # join authority.control_set acs on (are.control_set = acs.id) - # join authority.control_set_authority_field - # XXX wait what am I doing here? - my $authorities = $self->editor->json_query({ - "" + # Get all linked authority records themselves + my $linked_authorities = $self->editor->json_query({ + select => {are => [qw/id marc control_set/], aalink => ["target"]}, + from => { + aalink => { + are => { field => "id", fkey => "source" } + } + }, + where => {"+aalink" => {target => \@auth_ids}} }) or return; + + # Then use the linked authority records' control sets to find and + # pick out non-main-entry headings. Build the headings and make a + # combined data structure for the template's use. + + my %linked_headings_by_target; + + foreach my $row (@$linked_authorities) { + my $acsaf_list = + $self->ctx->{get_authority_fields}->($row->{control_set}); + + $row->{headings} = []; + # BEGIN isolate in eval? + my $record = new_from_xml MARC::Record($row->{marc}); + foreach my $acsaf (@$acsaf_list) { + my @fields = $record->field($acsaf->tag); + my @headings; + foreach (@fields) { + my $heading = ""; + foreach my $sf (split "", $acsaf->sf_list) { + $heading .= $_->subfield($sf) || ""; + } + push @headings, $heading; + } + + push @{$row->{headings}}, {$acsaf->id => \@headings}; + } + # END isolate in eval? + + $linked_headings_by_target{$row->{target}} = $row; + } + + # XXX TODO count bibs linked to each linked auth record? + print FH Dumper(\%linked_headings_by_target), "\n"; } + close FH; return 1; } @@ -103,14 +151,14 @@ sub load_browse_impl { $self->ctx->{browse_error} = 1; return; - }#elsif (not $self->flesh_browse_results($results)) { -# $logger->warn( -# "error in browse (flesh): " . $self->editor->event->{textcode} -# ); -# $self->ctx->{browse_error} = 1; -# -# return; -# } + } elsif (not $self->flesh_browse_results($results)) { + $logger->warn( + "error in browse (flesh): " . $self->editor->event->{textcode} + ); + $self->ctx->{browse_error} = 1; + + return; + } return $results; } 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 93cc3e120d..f2abacd3c8 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Util.pm @@ -18,7 +18,8 @@ our %cache = ( # cached data search_filter_groups => {en_us => {}}, aou_tree => {en_us => undef}, aouct_tree => {}, - eg_cache_hash => undef + eg_cache_hash => undef, + authority_fields => {en_us => {}} ); sub init_ro_object_cache { @@ -227,6 +228,17 @@ sub init_ro_object_cache { return $cache{org_settings}{$ctx->{locale}}{$org_id}{$setting}; }; + # retrieve and cache acsaf values + $ro_object_subs->{get_authority_fields} = sub { + my ($control_set) = @_; + + $cache{authority_fields}{$ctx->{locale}}{$control_set} = + $e->search_authority_control_set_authority_field({control_set => $control_set}) + unless exists $cache{authority_fields}{$ctx->{locale}}{$control_set}; + + return $cache{authority_fields}{$ctx->{locale}}{$control_set}; + }; + $ctx->{$_} = $ro_object_subs->{$_} for keys %$ro_object_subs; } diff --git a/Open-ILS/src/templates/opac/browse.tt2 b/Open-ILS/src/templates/opac/browse.tt2 index 9edf2bc575..3c4b6b4a78 100644 --- a/Open-ILS/src/templates/opac/browse.tt2 +++ b/Open-ILS/src/templates/opac/browse.tt2 @@ -83,7 +83,10 @@ [% FOR result IN ctx.browse_results %]
  • - [% result.value | html %] + [% result.value | html %] ([% result.sources %])
  • diff --git a/Open-ILS/src/templates/opac/parts/searchbar.tt2 b/Open-ILS/src/templates/opac/parts/searchbar.tt2 index 2034a9773e..52381a8ab6 100644 --- a/Open-ILS/src/templates/opac/parts/searchbar.tt2 +++ b/Open-ILS/src/templates/opac/parts/searchbar.tt2 @@ -7,7 +7,7 @@ [% l('Search the Catalog') %] [% l('Advanced Search') %] - [% l('Browse the Catalog') %] + [% l('Browse the Catalog') %]