From dc50f8de249132e1991fd91aed9147c08777a23c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 11 May 2023 12:38:53 +0200 Subject: [PATCH] Bug 33406: Handle ES search errors for authorities We are dealing ok with ES exceptions for biblio records search, catching them and raising them to the end user. But we don't for authorities, where we explode with an ugly 500. Test plan: Search for "(term_1*) AND (-) AND (term_2*)" in the authority search and notice that you don't get a 500 but an error instead saying that you should try again --- authorities/authorities-home.pl | 33 ++++++++++++------- .../modules/authorities/searchresultlist.tt | 4 +++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/authorities/authorities-home.pl b/authorities/authorities-home.pl index 2be064c1c21..3ef44e8b0ce 100755 --- a/authorities/authorities-home.pl +++ b/authorities/authorities-home.pl @@ -85,18 +85,6 @@ if ( $op eq "do_search" ) { my $resultsperpage = $query->param('resultsperpage') || 20; my $offset = ( $startfrom - 1 ) * $resultsperpage + 1; - my $builder = Koha::SearchEngine::QueryBuilder->new( - { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); - my $searcher = Koha::SearchEngine::Search->new( - { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); - my $search_query = $builder->build_authorities_query_compat( - [$marclist], [$and_or], [$excluding], [$operator], - [$value], $authtypecode, $orderby - ); - my ( $results, $total ) = $searcher->search_auth_compat( - $search_query, $offset, $resultsperpage - ); - ( $template, $loggedinuser, $cookie ) = get_template_and_user( { template_name => "authorities/searchresultlist.tt", @@ -106,6 +94,27 @@ if ( $op eq "do_search" ) { } ); + my $builder = Koha::SearchEngine::QueryBuilder->new( + { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); + my $searcher = Koha::SearchEngine::Search->new( + { index => $Koha::SearchEngine::AUTHORITIES_INDEX } ); + + my $search_query = $builder->build_authorities_query_compat( + [$marclist], [$and_or], [$excluding], [$operator], + [$value], $authtypecode, $orderby + ); + my ( $results, $total ); + eval { + ( $results, $total ) = $searcher->search_auth_compat( + $search_query, $offset, $resultsperpage + ); + }; + if ($@) { + my $query_error = q{}; + $query_error .= $@ if $@; + $template->param(query_error => $query_error); + } + $template->param( search_query => $search_query ) if C4::Context->preference('DumpSearchQueryTemplate'); $template->param( csrf_token => Koha::Token->new->generate_csrf({ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt index 42826d79282..3011dfb690e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/authorities/searchresultlist.tt @@ -43,6 +43,10 @@
+ [% IF ( query_error ) %] +

Error: [% query_error | html %]

+ [% END %] + [% IF ( total ) %]
[% pagination_bar | $raw %]
-- 2.25.1