From 04999df7b4c18acc3c27096376604d8077bdcf51 Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Sat, 23 Nov 2024 15:42:15 +0000 Subject: [PATCH] Bug 33296: Linker should search for authority records with an appropriate 008/14,15,16 value In an authority record, 008/14 = 'a' says it's appropriate for use as a main or added entry (1xx, 7xx), 008/15 = 'a' says it's appropriate for use as a subject entry, and 008/16 = 'a' says it's appropriate for use as a series entry. Test plan: ========== 1. Have a standard KTD environment. Have the patches from Bug 38494 applied. 2. Set AutoLinkBiblios system preference to 'Do', and ConsiderHeadingUse to 'Do'. 3. Open an existing bibliographic record and add a new field 650. In subfield $a enter 'Application software' (without quotes), and in $x 'Development.' (with final dot). 4. Save the record. In Normal view control that the entered subject heading entry has been linked with the existing authority record (note the magnifying glass icon). 5. Apply the patch ; restart all. 6. Repeat p. 3. Note that this time the newly entered subject heading entry has not been linked with the existing authority record. This is because the authority record has 008/15 = '|' while 'a' is required with ConsiderHeadingUse. 7. In Authorities, find the record for 'Application software--Development.' Modify it by changing 008/15 to 'a' (Heading use--subject added entry). 8. Return to the bibliographic record. Open it in the editor and save. The subject heading entry for 'Application software--Development.' should now be linked with the existing authority record. Signed-off-by: Roman Dolny --- C4/Heading.pm | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/C4/Heading.pm b/C4/Heading.pm index 79001ecf62..3200b0e3ab 100644 --- a/C4/Heading.pm +++ b/C4/Heading.pm @@ -22,7 +22,7 @@ use Modern::Perl; use MARC::Field; use C4::Context; use Module::Load qw( load ); -use List::Util qw( none ); +use List::Util qw( none first ); =head1 NAME @@ -206,6 +206,25 @@ sub _search { push @value, $thesaurus; } + if ( C4::Context->preference('ConsiderHeadingUse') ) { + my $marcflavour = C4::Context->preference('marcflavour'); + my $biblio_tag = $self->{'field'}->tag; + if ( $marcflavour eq 'MARC21' ) { + my $heading_use_search_field = + $biblio_tag =~ /^[127]/ ? 'Heading-use-main-or-added-entry' + : $biblio_tag =~ /^6/ ? 'Heading-use-subject-added-entry' + : $biblio_tag =~ /^[48]/ ? 'Heading-use-series-added-entry' + : undef; + if ($heading_use_search_field) { + push @marclist, $heading_use_search_field; + push @and_or, 'and'; + push @excluding, ''; + push @operator, 'is'; + push @value, 'a'; + } + } + } + require Koha::SearchEngine::QueryBuilder; require Koha::SearchEngine::Search; @@ -236,8 +255,8 @@ sub _search { ) ) { - pop @value; - push @value, 'notdefined'; + my $thesaurus_idx = first { $marclist[$_] eq 'thesaurus' } 0 .. $#marclist; + $value[$thesaurus_idx] = 'notdefined'; $search_query = $builder->build_authorities_query_compat( \@marclist, \@and_or, \@excluding, \@operator, \@value, $self->{'auth_type'}, -- 2.39.5