From 35fc25acc075bc10d0c9d0d148578df3256e441a Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 26 Oct 2022 10:46:12 +0000 Subject: [PATCH] Bug 31543: Use query string, rather than query, to build link This patch returns the query string from build_query_compat Under Zebra, either works for the link, for ES we need the simple string I expand the test for get_components_query to test both engines To test: 1.0) Set search engine to Elasticsearch 1.1) Go to Tools > Stage MARC records for import 1.2) Upload the example file 1.3) In the form, choose the format 'MARCXML' 1.4) Click 'Stage for import' 1.5) Click 'Manage staged records' 1.6) Click 'Import this batch into the catalog' 2) Change MaxComponentRecords to 10 3) In the staff interface, search the catalog for 'easy piano' 4) Click on the record 'Easy piano pieces for children' 5) Click on the 'show all component parts' link at the bottom of the Components tab --> it searches for HASH(...) - returns no results 6) Try the same in OPAC --> it searches for HASH(...) - returns no results 7) Apply patch and restart all 8) repeat 3-6 9) Results returned! Signed-off-by: David Nind --- Koha/Biblio.pm | 4 +-- catalogue/detail.pl | 4 +-- opac/opac-detail.pl | 4 +-- t/db_dependent/Koha/Biblio.t | 63 +++++++++++++++++++----------------- 4 files changed, 40 insertions(+), 35 deletions(-) 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"); - - 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); - - ( $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"); - - 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_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"); + foreach my $engine ('Zebra','Elasticsearch'){ + t::lib::Mocks::mock_preference( 'SearchEngine', $engine ); + + 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"); + + 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); + + ( $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"); + + 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 { -- 2.30.2