From 1f8924cb2754b4d3c156d21884e6f4b5ca09bd94 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 1 Jul 2022 11:08:57 +0000 Subject: [PATCH] Bug 31076: Handle year limits with equal sign or colon To test: 1 - Enable ES and index 2 - Set expandedSearchOption to 'show' 3 - Advanced search on staff and opac using Year field on staff and Publication date range on OPAC for: 2005 2005- -2005 <2005 >2005 2005-2010 4 - Confirm ranges don't work on staff side, but do on opac 5 - Apply patch 6 - Repeat searches - they work on both staff and opac 7 - prove t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t Signed-off-by: David Nind Signed-off-by: Fridolin Somers --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 8 ++++---- .../Koha/SearchEngine/Elasticsearch/QueryBuilder.t | 10 +++++++++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 860179ede3..27aabacd63 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -1062,14 +1062,14 @@ sub _fix_limit_special_cases { foreach my $l (@$limits) { # This is set up by opac-search.pl - if ( $l =~ /^yr,st-numeric,ge=/ ) { + if ( $l =~ /^yr,st-numeric,ge[=:]/ ) { my ( $start, $end ) = - ( $l =~ /^yr,st-numeric,ge=(.*) and yr,st-numeric,le=(.*)$/ ); + ( $l =~ /^yr,st-numeric,ge[=:](.*) and yr,st-numeric,le[=:](.*)$/ ); next unless defined($start) && defined($end); push @new_lim, "date-of-publication:[$start TO $end]"; } - elsif ( $l =~ /^yr,st-numeric=/ ) { - my ($date) = ( $l =~ /^yr,st-numeric=(.*)$/ ); + elsif ( $l =~ /^yr,st-numeric[=:]/ ) { + my ($date) = ( $l =~ /^yr,st-numeric[=:](.*)$/ ); next unless defined($date); $date = $self->_modify_string_by_type(type => 'st-year', operand => $date); push @new_lim, "date-of-publication:$date"; diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index c0084653c2..b11c667e4a 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -215,7 +215,7 @@ subtest 'build_authorities_query_compat() tests' => sub { }; subtest 'build_query tests' => sub { - plan tests => 59; + plan tests => 60; my $qb; @@ -339,6 +339,14 @@ subtest 'build_query tests' => sub { 'Open end year in year range of an st-year search is handled properly' ); + ( undef, $query ) = $qb->build_query_compat( undef, ['2019-'], ['yr,st-year'], + ['yr,st-numeric:-2019','yr,st-numeric:2005','yr,st-numeric:1984-2022'] ); + is( + $query->{query}{query_string}{query}, + '(date-of-publication:[2019 TO *]) AND (date-of-publication:[* TO 2019]) AND (date-of-publication:2005) AND (date-of-publication:[1984 TO 2022])', + 'Limit on year search is handled properly when colon used' + ); + # Enable auto-truncation t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' ); -- 2.35.4