From b1e6a168b7e39fa38c200b7e5a06eff3ee2a97c4 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 6 Aug 2021 17:01:38 +0100 Subject: [PATCH] Bug 11175: (QA follow-up) Fix queries Signed-off-by: Martin Renvoize Signed-off-by: Andrew Nugged --- Koha/Biblio.pm | 10 ++++++---- t/db_dependent/Koha/Biblio.t | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index ca4fcce9837..d32a9eff7cb 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -519,22 +519,24 @@ sub get_components_query { my $pf001 = $marc->field('001') || undef; if ( defined($pf001) ) { + $searchstr = "("; my $pf003 = $marc->field('003') || undef; 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 .= "("; + # search for (773$w='Host001' and 003='Host003') or 773$w='(Host003)Host001' $searchstr .= "(rcn:" . $pf001->data() . " AND cni:" . $pf003->data() . ")"; - $searchstr .= " OR rcn:" . $pf003->data() . " " . $pf001->data(); + $searchstr .= " OR rcn:\"" . $pf003->data() . " " . $pf001->data() . "\""; $searchstr .= ")"; } # limit to monograph and serial component part records $searchstr .= " AND (bib-level:a OR bib-level:b)"; + $searchstr .= ")"; } } else { diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index abe420a6dff..8b8f9635884 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -558,14 +558,14 @@ subtest 'get_components_query' => sub { C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); $biblio = Koha::Biblios->find( $biblio->biblionumber); - is($biblio->get_components_query, "rcn:$biblionumber AND (bib-level:a OR bib-level:b)", "UseControlNumber enabled without MarcOrgCode"); + is($biblio->get_components_query, "(rcn:$biblionumber AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled without MarcOrgCode"); my $marc_003_field = MARC::Field->new('003', 'OSt'); $record->append_fields($marc_003_field); C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); $biblio = Koha::Biblios->find( $biblio->biblionumber); - is($biblio->get_components_query, "((rcn:$biblionumber AND cni:OSt) OR rcn:OSt $biblionumber) AND (bib-level:a OR bib-level:b)", "UseControlNumber enabled with MarcOrgCode"); + is($biblio->get_components_query, "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled with MarcOrgCode"); }; subtest 'orders() and active_orders() tests' => sub { -- 2.25.1