From 7f99e6d5b0ce36776ab7957035f937e01dacb6a6 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Thu, 1 Oct 2020 15:01:02 +0000 Subject: [PATCH] Bug 26537: use QueryBuilder in unimarc_field_4XX plugin to make query --- cataloguing/value_builder/unimarc_field_4XX.pl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cataloguing/value_builder/unimarc_field_4XX.pl b/cataloguing/value_builder/unimarc_field_4XX.pl index e157687..fafce98 100755 --- a/cataloguing/value_builder/unimarc_field_4XX.pl +++ b/cataloguing/value_builder/unimarc_field_4XX.pl @@ -36,6 +36,7 @@ use Koha::ItemTypes; use Koha::SearchEngine; use Koha::SearchEngine::Search; +use Koha::SearchEngine::QueryBuilder; sub plugin_parameters { my ( $dbh, $record, $tagslib, $i, $tabloop ) = @_; @@ -358,10 +359,13 @@ sub plugin { my $startfrom = $query->param('startfrom'); my $resultsperpage = $query->param('resultsperpage') || 20; my $orderby; - my $op = 'and'; - $search = 'kw:'.$search." $op mc-itemtype:".$itype if $itype; + my $limits = $itype ? ["mc-itype,phr:$itype"] : []; + + my $builder = Koha::SearchEngine::QueryBuilder->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); - my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat($search, $startfrom * $resultsperpage, $resultsperpage ); + + my ($builderror, $es_query)= $builder->build_query_compat( undef, [$search], ['kw'], $limits, ['relevance']); + my ( $errors, $results, $total_hits ) = $searcher->simple_search_compat($es_query, $startfrom * $resultsperpage, $resultsperpage ); if (defined $errors ) { $results = []; } @@ -459,7 +463,7 @@ sub plugin { if ( $total_hits < $from + $resultsperpage ) { $to = $total_hits; }else{ - $to = $from + $resultsperpage ; + $to = $startfrom * $resultsperpage + $resultsperpage ; } my $defaultview = 'BiblioDefaultView' . C4::Context->preference('BiblioDefaultView'); -- 2.7.4