From ae6ec2e91223bdef58dfc85fce4dee4c5379ede6 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 14 Apr 2020 13:08:14 -0400 Subject: [PATCH] LPXXX Browse expanded headings details WIP Signed-off-by: Bill Erickson --- .../lib/OpenILS/Application/Search/Browse.pm | 97 +++++++++++++++------- 1 file changed, 66 insertions(+), 31 deletions(-) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Browse.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Browse.pm index 803f08b054..0aacf4aef2 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Browse.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Search/Browse.pm @@ -305,49 +305,36 @@ sub find_authority_headings_and_notes { extract_public_general_notes($record, $row); - # extract headings from the main authority record along with their - # types - my $parsed_headings = new_editor()->json_query({ - from => ['authority.extract_headings', $row->{marc}] - }); - my %heading_type_map = (); - if ($parsed_headings) { - foreach my $h (@$parsed_headings) { - $heading_type_map{$h->{normalized_heading}} = - $h->{purpose} eq 'variant' ? 'variant' : - $h->{purpose} eq 'related' ? $h->{related_type} : - ''; - } - } - - # By applying grep in this way, we get acsaf objects that *have* and - # therefore *aren't* main entries, which is what we want. foreach my $acsaf (values(%$acsaf_table)) { my @fields = $record->field($acsaf->tag); my %sf_lookup = map { $_ => 1 } split("", $acsaf->display_sf_list); my @headings; foreach my $field (@fields) { - my $h = { main_entry => ( $acsaf->main_entry ? 0 : 1 ), - heading => get_authority_heading($field, \%sf_lookup, $acsaf->joiner) }; - my $norm = search_normalize($h->{heading}); - if (exists $heading_type_map{$norm}) { - $h->{type} = $heading_type_map{$norm}; - } - # XXX I was getting "target" from authority.authority_linking, but - # that makes no sense: that table can only tell you that one - # authority record as a whole points at another record. It does - # not record when a specific *field* in one authority record - # points to another record (not that it makes much sense for - # one authority record to have links to multiple others, but I can't - # say there definitely aren't cases for that). + # If a field has a main_entry, it's not itself a main entry. + my $h = {main_entry => $acsaf->main_entry ? 0 : 1}; + $h->{target} = $2 if ($field->subfield('0') || "") =~ /(^|\))(\d+)$/; - # The target is the row id if this is a main entry... + # The target is the main authority ID on the current row + # if this is a main entry. $h->{target} = $row->{id} if $h->{main_entry}; + # We're not interested in See's that do not refer to a + # local authority record. + next unless $h->{target}; + + $h->{heading} = + get_authority_heading($field, \%sf_lookup, $acsaf->joiner); + + if ($acsaf->tag =~ /^4/) { + add_4xx_info($h, $field); + } elsif ($acsaf->tag =~ /^[57]/) { + add_5xx_7xx_info($h, $field, $record); + } + push @headings, $h; } @@ -357,6 +344,54 @@ sub find_authority_headings_and_notes { return $row; } +sub add_4xx_info { + my ($heading, $marc_field) = @_; + + my $w = $marc_field->subfield('w'); + $heading->{variant_type} = $w eq 'd' ? 'acronym' : 'other'; +} + +sub add_5xx_7xx_info { + my ($heading, $marc_field, $record) = @_; + + my $w_full = $marc_field->subfield('w'); + my $w = substr($w_full, 0, 1); + + my $tag = $marc_field->tag; + + my $related_type = 'other'; + + if ($tag =~ /^7/ && $tag ne '730') { + $related_type = 'equivalent'; + + } elsif ($tag ne '530') { + + my %w_map = ( + a => 'earlier', + b => 'later', + t => 'parentOrg', + g => 'broader', + h => 'narrower' + ); + + $related_type = $w_map{$w} if $w_map{$w}; + } + + $heading->{related_type} = $related_type; + + if ($w eq 'r') { + $heading->{relationship_designation} = + $marc_field->subfield('i') || $marc_field->subfield('4'); + + } elsif ($w_full =~ /...c/) { + $heading->{complex_see_also} = $record->field('663')->subfield('a'); + + } elsif ($w_full =~ /...d/) { + my @histories = $record->field('665')->subfield('a'); + $heading->{history_reference} = join(' ', @histories); + } +} + # Break out any Public General Notes (field 680) for display. These are # sometimes (erroneously?) called "scope notes." I say erroneously, -- 2.11.0