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 <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit a813de5f85)
Signed-off-by: Jacob O'Mara <jacob.omara@ptfs-europe.com>
This commit is contained in:
Johanna Raisa 2022-08-09 11:58:59 +03:00 committed by Jacob O'Mara
parent 1ca1e4dc9d
commit 15bd6e96bc
2 changed files with 4 additions and 4 deletions

View file

@ -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 .= ")";
}

View file

@ -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);
}