announce("Start $start_time for all records");
}
-# given a set of authority record ID's and a controlled bib field
-# indicator 2 (thesaurus) value, returns the ID of the first
-# authority record in the set that matches the thesaurus.
+# given a set of authority record ID's and a controlled bib field,
+# returns the ID of the first authority record in the set that
+# matches the thesaurus spec of the bib record.
sub find_matching_auth_for_thesaurus {
my ($e, $bib_field, $auth_ids) = @_;
+ # bib field thesaurus spec
my $cfield_ind2 = $bib_field->indicator(2);
announce("6XX indicator 2 value = $cfield_ind2");
+ my $is_local = 0;
if ($cfield_ind2 eq '7') {
# subject thesaurus code is embedded in the bib field subfield 2
+
+ $is_local = 1;
my $thesaurus = $bib_field->subfield('2') || '';
announce("Found local thesaurus value $thesaurus");
- # if no remapping is found, use 7 == Other.
+ # if we have no special remapping value for the found thesaurus,
+ # fall back to ind2 => 7=Other.
$cfield_ind2 = $REMAP_BIB_SF2_TO_IND2{$thesaurus} || '7';
- announce("Local thesaurus '$thesaurus' mapped to ind2 value '$cfield_ind2'");
+
+ announce("Local thesaurus '$thesaurus' ".
+ "remapped to ind2 value '$cfield_ind2'");
}
my $auth_leaders = $e->json_query({
where => {'+afr' => {tag => '008', record => $auth_ids}}
});
+ my $authz_found = undef;
for my $leader (@$auth_leaders) {
my $value = $leader->{value};
next unless $value;
+
my $thesaurus = substr($value, 11, 1); # leader/11 -- zero based.
+
+ # Note for later that we encountered an authority record
+ # whose thesaurus values is z=Other.
+ $authz_found = $leader->{record} if $thesaurus eq 'z';
+
if ($AUTH_TO_BIB_IND2{$thesaurus} eq $cfield_ind2) {
announce("Found a match on thesaurus ".
"'$thesaurus' for " . $leader->{record});
}
}
+ # If the bib field in question has a locally encoded thesaurus
+ # (ind2=7) and no auth record was found above via remapped
+ # thesaurus value, use the authority record with thesaurus z=Other.
+ return $authz_found if $is_local;
+
return undef;
}