diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 3c8e5cb4b2..5b7541a36e 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -616,13 +616,13 @@ sub get_components_query { $cleaned_title = $builder->clean_search_term($cleaned_title); $searchstr = qq#Host-item:("$cleaned_title")#; } - my ($error, $query_str) = $builder->build_query_compat( undef, [$searchstr], undef, undef, [$sort], 0 ); + my ($error, $query ,$query_str) = $builder->build_query_compat( undef, [$searchstr], undef, undef, [$sort], 0 ); if( $error ){ warn $error; return; } - return ($query_str, $sort); + return ($query, $query_str, $sort); } =head3 subscriptions diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 5cb556ae05..c7908bc969 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -265,8 +265,8 @@ if ( $showcomp eq 'both' || $showcomp eq 'staff' ) { ); } $template->param( ComponentParts => $parts ); - my ( $comp_query, $comp_sort ) = $biblio->get_components_query; - my $cpq = $comp_query . "&sort_by=" . $comp_sort; + my ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query; + my $cpq = $comp_query_str . "&sort_by=" . $comp_sort; $template->param( ComponentPartsQuery => $cpq ); } } else { # check if we should show analytics anyway diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 1e74df6279..961be88143 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -616,8 +616,8 @@ if ( $showcomp eq 'both' || $showcomp eq 'opac' ) { ); } $template->param( ComponentParts => $parts ); - my ( $comp_query, $comp_sort ) = $biblio->get_components_query; - my $cpq = $comp_query . "&sort_by=" . $comp_sort; + my ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query; + my $cpq = $comp_query_str . "&sort_by=" . $comp_sort; $template->param( ComponentPartsQuery => $cpq ); } } else { # check if we should show analytics anyway diff --git a/t/db_dependent/Koha/Biblio.t b/t/db_dependent/Koha/Biblio.t index 98eac9b64f..ac9fcd0466 100755 --- a/t/db_dependent/Koha/Biblio.t +++ b/t/db_dependent/Koha/Biblio.t @@ -562,40 +562,45 @@ subtest 'get_marc_components() tests' => sub { }; subtest 'get_components_query' => sub { - plan tests => 6; + plan tests => 12; my $biblio = $builder->build_sample_biblio(); my $biblionumber = $biblio->biblionumber; my $record = $biblio->metadata->record; - t::lib::Mocks::mock_preference( 'UseControlNumber', '0' ); - t::lib::Mocks::mock_preference( 'ComponentSortField', 'author' ); - t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'za' ); - my ( $comp_q, $comp_s ) = $biblio->get_components_query; - is($comp_q, 'Host-item:("Some boring read")', "UseControlNumber disabled"); - is($comp_s, "author_za", "UseControlNumber disabled sort is correct"); + foreach my $engine ('Zebra','Elasticsearch'){ + t::lib::Mocks::mock_preference( 'SearchEngine', $engine ); - t::lib::Mocks::mock_preference( 'UseControlNumber', '1' ); - t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'az' ); - my $marc_001_field = MARC::Field->new('001', $biblionumber); - $record->append_fields($marc_001_field); - C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); - $biblio = Koha::Biblios->find( $biblio->biblionumber); + t::lib::Mocks::mock_preference( 'UseControlNumber', '0' ); + t::lib::Mocks::mock_preference( 'ComponentSortField', 'author' ); + t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'za' ); + my ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query; + is($comp_query_str, 'Host-item:("Some boring read")', "$engine: UseControlNumber disabled"); + is($comp_sort, "author_za", "$engine: UseControlNumber disabled sort is correct"); - ( $comp_q, $comp_s ) = $biblio->get_components_query; - is($comp_q, "(rcn:$biblionumber AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled without MarcOrgCode"); - is($comp_s, "author_az", "UseControlNumber enabled without MarcOrgCode sort is correct"); + t::lib::Mocks::mock_preference( 'UseControlNumber', '1' ); + t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'az' ); + my $marc_001_field = MARC::Field->new('001', $biblionumber); + $record->append_fields($marc_001_field); + C4::Biblio::ModBiblio( $record, $biblio->biblionumber ); + $biblio = Koha::Biblios->find( $biblio->biblionumber); - 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); + ( $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_sort, "author_az", "$engine: UseControlNumber enabled without MarcOrgCode sort is correct"); - t::lib::Mocks::mock_preference( 'ComponentSortField', 'title' ); - t::lib::Mocks::mock_preference( 'ComponentSortOrder', 'asc' ); - ( $comp_q, $comp_s ) = $biblio->get_components_query; - is($comp_q, "(((rcn:$biblionumber AND cni:OSt) OR rcn:\"OSt $biblionumber\") AND (bib-level:a OR bib-level:b))", "UseControlNumber enabled with MarcOrgCode"); - is($comp_s, "title_asc", "UseControlNumber enabled with MarcOrgCode sort if correct"); + 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); + + 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_sort, "title_asc", "$engine: UseControlNumber enabled with MarcOrgCode sort if correct"); + $record->delete_field($marc_003_field); + } }; subtest 'orders() and active_orders() tests' => sub {