From eaf9767cd2dd1066c50d7fc3828761897624438e Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 14 Nov 2024 05:44:59 +0000 Subject: [PATCH] Bug 30745: (QA follow-up) tidy Signed-off-by: David Cook --- .../Elasticsearch/QueryBuilder.pm | 12 +++--- labels/label-item-search.pl | 40 +++++++++---------- .../SearchEngine/Elasticsearch/QueryBuilder.t | 28 ++++++++----- 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 874f73316a..ad240bdde6 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -854,10 +854,9 @@ sub _modify_string_by_type { my $until = $2 || '*'; $str = "[$from TO $until]"; } - } - elsif($type eq 'st-date-normalized'){ - if ($str =~ /^(.*) - (.*)$/) { - my $from = $1 || '*'; + } elsif ( $type eq 'st-date-normalized' ) { + if ( $str =~ /^(.*) - (.*)$/ ) { + my $from = $1 || '*'; my $until = $2 || '*'; $str = "[$from TO $until]"; } @@ -1171,11 +1170,10 @@ sub _fix_limit_special_cases { else { push @new_lim, $term; } - } - elsif ($l =~ /^acqdate,st-date-normalized=/ ) { + } elsif ( $l =~ /^acqdate,st-date-normalized=/ ) { my ($date) = ( $l =~ /^acqdate,st-date-normalized=(.*)$/ ); next unless defined($date); - $date = $self->_modify_string_by_type(type => 'st-date-normalized', operand => $date); + $date = $self->_modify_string_by_type( type => 'st-date-normalized', operand => $date ); push @new_lim, "date-of-acquisition.raw:$date"; } else { diff --git a/labels/label-item-search.pl b/labels/label-item-search.pl index 46a36c6e93..6de50862f1 100755 --- a/labels/label-item-search.pl +++ b/labels/label-item-search.pl @@ -40,7 +40,7 @@ my $query = CGI->new; my $type = $query->param('type'); my $op = $query->param('op') || ''; my $batch_id = $query->param('batch_id'); -my @limits = split(" AND ", $query->param('limits') || ""); +my @limits = split( " AND ", $query->param('limits') || "" ); my $startfrom = $query->param('startfrom') || 1; my ($template, $loggedinuser, $cookie) = (undef, undef, undef); my ( @@ -63,33 +63,31 @@ if ( $op eq "do_search" ) { $datefrom = $query->param('datefrom'); $dateto = $query->param('dateto'); - my $builder = Koha::SearchEngine::QueryBuilder->new( - { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); - my $searcher = Koha::SearchEngine::Search->new( - { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); + my $builder = Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); + my $searcher = Koha::SearchEngine::Search->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); - if (!@limits) { - push(@limits, "acqdate,st-date-normalized=$datefrom - $dateto"); + if ( !@limits ) { + push( @limits, "acqdate,st-date-normalized=$datefrom - $dateto" ); } - my ( $build_error, $query, $simple_query, $query_cgi, - $query_desc, $limit, $limit_cgi, $limit_desc, - $query_type ) - = $builder->build_query_compat( undef, [$ccl_textbox], [$idx], \@limits); + my ( + $build_error, $query, $simple_query, $query_cgi, + $query_desc, $limit, $limit_cgi, $limit_desc, + $query_type + ) = $builder->build_query_compat( undef, [$ccl_textbox], [$idx], \@limits ); my $offset = $startfrom > 1 ? $startfrom - 1 : 0; my ( $error, $results, $facets ) = $searcher->search_compat( - $query, $simple_query, [], ['biblioserver'], $resultsperpage, $offset, - undef, undef, $query_type, undef + $query, $simple_query, [], ['biblioserver'], $resultsperpage, $offset, + undef, undef, $query_type, undef ); - if (!defined $error && defined($results) && @{$results->{biblioserver}{RECORDS}} > 0 ) { - $show_results = grep { defined $_ } @{$results->{biblioserver}{RECORDS}}; - $marcresults = [ grep { defined $_ } @{$results->{biblioserver}{RECORDS}} ]; - $total_hits = $results->{biblioserver}{hits}; - } - else { + if ( !defined $error && defined($results) && @{ $results->{biblioserver}{RECORDS} } > 0 ) { + $show_results = grep { defined $_ } @{ $results->{biblioserver}{RECORDS} }; + $marcresults = [ grep { defined $_ } @{ $results->{biblioserver}{RECORDS} } ]; + $total_hits = $results->{biblioserver}{hits}; + } else { Koha::Logger->get->warn("ERROR label-item-search: no results from simple_search_compat"); # leave $show_results undef @@ -192,13 +190,13 @@ if ($show_results) { ); $template->param( - results => ($show_results ? 1 : 0), + results => ( $show_results ? 1 : 0 ), result_set => \@results_set, batch_id => $batch_id, type => $type, idx => $idx, ccl_textbox => $ccl_textbox, - limits => join(" AND ", @limits), + limits => join( " AND ", @limits ), ); } diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index 340eb41424..ca0e3666b6 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -671,34 +671,42 @@ subtest 'build_query tests' => sub { is( $limit_cgi,'&limit=author%3ADillinger%20Escaplan&limit=mc-itype%2Cphr%3ABOOK&limit=mc-itype%2Cphr%3ACD', "Limit CGI formed correctly when no search terms"); is( $limit_desc,'(author:("Dillinger Escaplan")) AND itype:(("BOOK") OR ("CD"))',"Limit desc formed correctly when no search terms"); - ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'], - ['acqdate,st-date-normalized= - '] ); + ( undef, $query ) = $qb->build_query_compat( + undef, ['barcode123123'], ['bc'], + ['acqdate,st-date-normalized= - '] + ); is( $query->{query}{query_string}{query}, '(barcode:barcode123123) AND date-of-acquisition.raw:[* TO *]', 'If no date all date-of-acquisition are selected' ); - ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'], - ['acqdate,st-date-normalized=2024-08-01 - '] ); + ( undef, $query ) = $qb->build_query_compat( + undef, ['barcode123123'], ['bc'], + ['acqdate,st-date-normalized=2024-08-01 - '] + ); is( $query->{query}{query_string}{query}, '(barcode:barcode123123) AND date-of-acquisition.raw:[2024-08-01 TO *]', 'Open start date in date range of an st-date-normalized search is handled properly' ); - ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'], - ['acqdate,st-date-normalized= - 2024-08-30'] ); + ( undef, $query ) = $qb->build_query_compat( + undef, ['barcode123123'], ['bc'], + ['acqdate,st-date-normalized= - 2024-08-30'] + ); is( $query->{query}{query_string}{query}, '(barcode:barcode123123) AND date-of-acquisition.raw:[* TO 2024-08-30]', 'Open end date in date range of an st-date-normalized search is handled properly' ); - ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'], - ['acqdate,st-date-normalized=2024-08-01 - 2024-08-30'] ); - is( - $query->{query}{query_string}{query}, + ( undef, $query ) = $qb->build_query_compat( + undef, ['barcode123123'], ['bc'], + ['acqdate,st-date-normalized=2024-08-01 - 2024-08-30'] + ); + is( + $query->{query}{query_string}{query}, '(barcode:barcode123123) AND date-of-acquisition.raw:[2024-08-01 TO 2024-08-30]', 'Date range in an st-date-normalized search is handled properly' ); -- 2.39.5