From 15bd6e96bc0c365c8695fc01c633e53eb6095778 Mon Sep 17 00:00:00 2001 From: Johanna Raisa Date: Tue, 9 Aug 2022 11:58:59 +0300 Subject: [PATCH] Bug 31326: Koha::Biblio->get_components_query fetches too many component parts This patch adds double quotes to rcn and cni when searching component parts with get_components_query. Test plan: 1) Apply the patch 2) prove Koha/t/db_dependent/Koha/Biblio.t Sponsored-by: Koha-Suomi Oy Signed-off-by: David Nind Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi (cherry picked from commit a813de5f85c221974b2187259e25150ca7f44534) Signed-off-by: Jacob O'Mara --- Koha/Biblio.pm | 4 ++-- t/db_dependent/Koha/Biblio.t | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 06d0e86c7f..5bf369cd6a 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -595,12 +595,12 @@ sub get_components_query { if ( !defined($pf003) ) { # search for 773$w='Host001' - $searchstr .= "rcn:" . $pf001->data(); + $searchstr .= "rcn:\"" . $pf001->data()."\""; } else { $searchstr .= "("; # search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001' - $searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")"; + $searchstr .= "(rcn:\"" . $pf001->data() . "\" AND cni:\"" . $pf003->data() . "\")"; $searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\""; $searchstr .= ")"; } diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index ac9fcd0466..67513cd09f 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -586,7 +586,7 @@ subtest 'get_components_query' => sub { $biblio = Koha::Biblios->find( $biblio->biblionumber); ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query; - is($comp_query_str, "(rcn:$biblionumber AND (bib-level:a OR bib-level:b))", "$engine: UseControlNumber enabled without MarcOrgCode"); + is($comp_query_str, "(rcn:\"$biblionumber\" AND (bib-level:a OR bib-level:b))", "$engine: UseControlNumber enabled without MarcOrgCode"); is($comp_sort, "author_az", "$engine: UseControlNumber enabled without MarcOrgCode sort is correct"); my $marc_003_field = MARC::Field->new('003', 'OSt'); @@ -597,7 +597,7 @@ subtest 'get_components_query' => sub { t::lib::Mocks::mock_preference( 'ComponentSortField', 'title' ); t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'asc' ); ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query; - is($comp_query_str, "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") AND (bib-level:a OR bib-level:b))", "$engine: UseControlNumber enabled with MarcOrgCode"); + is($comp_query_str, "(((rcn:\"$biblionumber\" AND cni:\"OSt\") OR rcn:\"OSt $biblionumber\") AND (bib-level:a OR bib-level:b))", "$engine: UseControlNumber enabled with MarcOrgCode"); is($comp_sort, "title_asc", "$engine: UseControlNumber enabled with MarcOrgCode sort if correct"); $record->delete_field($marc_003_field); } -- 2.39.5