From 12049ef14f1bf54f7061b1d5a672bb7e71c20f99 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Thu, 12 May 2022 17:29:52 +0200 Subject: [PATCH] Bug 30745: handle ES ranges for date of acquisition Test plan: - Enable elasticsearch - git to labels/label-item-search.pl - search using after date only => check you get items with date-of-acquisition greater than after date - search using before date only => check you get items with date-of-acquisition less than before date - search using after and before date => check you get items with date-of-acquisition between after and before - Combine this searches with a specified index - enable zebra and repeat these tests Signed-off-by: Andrew Fuerste-Henry --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 17 +++++++++++++++++ labels/label-item-search.pl | 14 ++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index dba475eb3c..b489a62a97 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -1052,6 +1052,7 @@ sub _fix_limit_special_cases { my ( $self, $limits ) = @_; my @new_lim; + my $ranges; foreach my $l (@$limits) { # This is set up by opac-search.pl @@ -1096,6 +1097,16 @@ sub _fix_limit_special_cases { elsif ( $l =~ /^available$/ ) { push @new_lim, 'onloan:false'; } + elsif ($l =~ /^acqdate,(ge|le),st-date-normalized=/ ) { + my ($fromdate) = ( $l =~ /^acqdate,ge,st-date-normalized=(.*)$/ ); + my ($todate) = ( $l =~ /^acqdate,le,st-date-normalized=(.*)$/ ); + $fromdate ||= '*'; + $todate ||= '*'; + $ranges->{'date-of-acquisition.raw'} = { + from => $fromdate, + to => $todate + } + } else { my ( $field, $term ) = $l =~ /^\s*([\w,-]*?):(.*)/; $field =~ s/,phr$//; #We are quoting all the limits as phrase, this prevents from quoting again later @@ -1106,6 +1117,12 @@ sub _fix_limit_special_cases { push @new_lim, $l; } } + + if ( $ranges ) { + foreach my $index ( keys %$ranges ) { + push @new_lim, "$index:[$ranges->{$index}{from} TO $ranges->{$index}{to}]" + } + } } return \@new_lim; } diff --git a/labels/label-item-search.pl b/labels/label-item-search.pl index a66b63bb74..dd19bd0d34 100755 --- a/labels/label-item-search.pl +++ b/labels/label-item-search.pl @@ -33,6 +33,7 @@ use Koha::Logger; use Koha::DateUtils qw( dt_from_string output_pref ); use Koha::Items; use Koha::ItemTypes; +use Koha::SearchEngine::QueryBuilder; use Koha::SearchEngine::Search; my $query = CGI->new; @@ -85,20 +86,21 @@ if ( $op eq "do_search" ) { } } - my ( $error, $query, $simple_query, $query_cgi, + 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, $marcresults, $facets ) = $searcher->search_compat( - $query, $simple_query, undef, ['biblioserver'], $resultsperpage, $offset, + my ( $error, $results, $facets ) = $searcher->search_compat( + $query, $simple_query, [], ['biblioserver'], $resultsperpage, $offset, undef, undef, $query_type, undef - ); + ); - if (!defined $error && $marcresults->{biblioserver}{RECORDS} ) { - $show_results = $marcresults->{biblioserver}{RECORDS}; + if (!defined $error && @{$results->{biblioserver}{RECORDS}} ) { + $show_results = @{$results->{biblioserver}{RECORDS}}; + $marcresults = $results->{biblioserver}{RECORDS}; } else { Koha::Logger->get->warn("ERROR label-item-search: no results from simple_search_compat"); -- 2.30.2