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;
+ foreach my $field (@fields) {
+ my $h = {
+ heading => join(
+ "", grep(
+ defined,
+ map { $field->subfield($_) } split("", $acsaf->sf_list)
+ )
+ )
+ };
+
+ # 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).
+ ($field->subfield('0') || "") =~ /(^|\))(\d+)$/;
+
+ $h->{target} = $2 if defined $2;
+ push @headings, $h;
}
# Remember: main_entry is a link field, so for it to evaluate
return $row;
}
+sub map_authority_headings_to_results {
+ my ($self, $linked, $results) = @_;
+
+ # 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_auth_id = map {
+ $_->{id} => $self->find_authority_headings($_)
+ } @$linked;
+
+ # Graft this authority heading data onto our main result set at the
+ # "authorities" column.
+ foreach my $row (@$results) {
+ $row->{authorities} = [
+ map { $linked_headings_by_auth_id{$_} } @{$row->{authorities}}
+ ];
+ }
+}
+
# 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).
if (@auth_ids) {
# Get all linked authority records themselves
my $linked = $self->editor->json_query({
- select => {are => [qw/id marc control_set/], aalink => ["target"]},
- from => {
- aalink => {
- are => { field => "id", fkey => "source" }
- }
+ select => {
+ are => [qw/id marc control_set/]
},
- where => {"+aalink" => {target => \@auth_ids}}
+ from => { are => { } },
+ where => {"+are" => {id => \@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_auth_id =
- map { $_->{id} => $self->find_authority_headings($_) } @$linked;
-
- # Graft this authority heading data onto our main result set at the
- # "authorities" column.
- foreach my $row (@$results) {
- $row->{authorities} = [
- map { $linked_headings_by_auth_id{$_} } @{$row->{authorities}}
- ];
- }
+ $self->map_authority_headings_to_results($linked, $results);
# Get use counts of authority records, i.e. number of bibs linked to
# them. - XXX refine later to consider holdings visibility.