From c66d525e587127e2b50d06808686c434b3babb87 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Thu, 12 May 2022 11:56:04 +0200 Subject: [PATCH] Bug 30745: Use query builder and search_compat in label-item-search Test plan: - apply this patch, - make some searches in labels/label-item-search.pl using the 3 form input (index, after date, before date), - check it works like before Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Katrin Fischer https://bugs.koha-community.org/show_bug.cgi?id=30845 --- labels/label-item-search.pl | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/labels/label-item-search.pl b/labels/label-item-search.pl index 4dba30276d..d0624e4e2d 100755 --- a/labels/label-item-search.pl +++ b/labels/label-item-search.pl @@ -58,29 +58,38 @@ my $display_columns = [ {_add => {label => "Add Item", link_fi if ( $op eq "do_search" ) { $idx = $query->param('idx'); $ccl_textbox = $query->param('ccl_textbox'); - if ( $ccl_textbox && $idx ) { - $ccl_query = "$idx:$ccl_textbox"; - } $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 @limits; if ($datefrom) { - $ccl_query .= ' AND ' if $ccl_textbox; - $ccl_query .= "acqdate,ge,st-date-normalized=" . $datefrom; + push(@limits, "acqdate,ge,st-date-normalized=$datefrom"); } if ($dateto) { - $ccl_query .= ' AND ' if ( $ccl_textbox || $datefrom ); - $ccl_query .= "acqdate,le,st-date-normalized=" . $dateto; + push(@limits, "acqdate,le,st-date-normalized=$dateto"); } + my ( $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 $searcher = Koha::SearchEngine::Search->new({index => 'biblios'}); - ( $error, $marcresults, $total_hits ) = $searcher->simple_search_compat($ccl_query, $offset, $resultsperpage); - if (!defined $error && @{$marcresults} ) { - $show_results = @{$marcresults}; + my ( $error, $marcresults, $facets ) = $searcher->search_compat( + $query, $simple_query, undef, ['biblioserver'], $resultsperpage, $offset, + undef, undef, $query_type, undef + ); + + if (!defined $error && $marcresults->{biblioserver}{RECORDS} ) { + $show_results = $marcresults->{biblioserver}{RECORDS}; } else { Koha::Logger->get->warn("ERROR label-item-search: no results from simple_search_compat"); -- 2.34.1