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 <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 17:29:52 +02:00 committed by Katrin Fischer
parent e0230f6e6f
commit b06e648de7
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
2 changed files with 25 additions and 6 deletions

View File

@ -1098,6 +1098,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
if ( $l =~ /^yr,st-numeric,ge[=:]/ ) {
@ -1165,6 +1166,16 @@ sub _fix_limit_special_cases {
push @new_lim, $term;
}
}
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
@ -1175,6 +1186,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;
}

View File

@ -32,6 +32,7 @@ use C4::Creators::Lib qw( html_table );
use Koha::Logger;
use Koha::Items;
use Koha::ItemTypes;
use Koha::SearchEngine::QueryBuilder;
use Koha::SearchEngine::Search;
my $query = CGI->new;
@ -76,20 +77,21 @@ if ( $op eq "do_search" ) {
push(@limits, "acqdate,le,st-date-normalized=$dateto");
}
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");