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 <andrew@bywatersolutions.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

https://bugs.koha-community.org/show_bug.cgi?id=30845
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: David Cook <dcook@prosentient.com.au>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Alex Arnaud 2022-05-12 11:56:04 +02:00 committed by Katrin Fischer
parent 361b908031
commit e0230f6e6f
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 21 additions and 12 deletions

View File

@ -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 $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);
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);
if (!defined $error && @{$marcresults} ) {
$show_results = @{$marcresults};
my $offset = $startfrom > 1 ? $startfrom - 1 : 0;
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");