Bugzilla – Attachment 171006 Details for
Bug 30745
Elasticsearch: Search never returns with after-date and/or before-date in label batch item search
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30745: (follow-up) adding some handling for st-date-normalized and adding unit tests
Bug-30745-follow-up-adding-some-handling-for-st-da.patch (text/plain), 5.59 KB, created by
Hammat wele
on 2024-09-03 21:40:09 UTC
(
hide
)
Description:
Bug 30745: (follow-up) adding some handling for st-date-normalized and adding unit tests
Filename:
MIME Type:
Creator:
Hammat wele
Created:
2024-09-03 21:40:09 UTC
Size:
5.59 KB
patch
obsolete
>From 86031c6c7b8dc799e5b7d0533612b19e1266b5bc Mon Sep 17 00:00:00 2001 >From: Hammat Wele <hammat.wele@inlibro.com> >Date: Mon, 26 Aug 2024 17:44:35 +0000 >Subject: [PATCH] Bug 30745: (follow-up) adding some handling for > st-date-normalized and adding unit tests > >--- > .../Elasticsearch/QueryBuilder.pm | 27 +++++++-------- > labels/label-item-search.pl | 3 +- > .../SearchEngine/Elasticsearch/QueryBuilder.t | 34 ++++++++++++++++++- > 3 files changed, 46 insertions(+), 18 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index 8298520835..4b695b0e0c 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -849,6 +849,13 @@ sub _modify_string_by_type { > $str = "[$from TO $until]"; > } > } >+ elsif($type eq 'st-date-normalized'){ >+ if ($str =~ /^(.*) - (.*)$/) { >+ my $from = $1 || '*'; >+ my $until = $2 || '*'; >+ $str = "[$from TO $until]"; >+ } >+ } > return $str; > } > >@@ -1087,7 +1094,6 @@ 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[=:]/ ) { >@@ -1155,15 +1161,11 @@ 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 >- } >+ elsif ($l =~ /^acqdate,st-date-normalized=/ ) { >+ my ($date) = ( $l =~ /^acqdate,st-date-normalized=(.*)$/ ); >+ next unless defined($date); >+ $date = $self->_modify_string_by_type(type => 'st-date-normalized', operand => $date); >+ push @new_lim, "date-of-acquisition.raw:$date"; > } > else { > my ( $field, $term ) = $l =~ /^\s*([\w,-]*?):(.*)/; >@@ -1176,11 +1178,6 @@ sub _fix_limit_special_cases { > } > } > >- 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 765119f4f9..990d62544b 100755 >--- a/labels/label-item-search.pl >+++ b/labels/label-item-search.pl >@@ -69,8 +69,7 @@ if ( $op eq "do_search" ) { > { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); > > if (!@limits) { >- push(@limits, "acqdate,ge,st-date-normalized=$datefrom") if ($datefrom); >- push(@limits, "acqdate,le,st-date-normalized=$dateto") if ($dateto); >+ push(@limits, "acqdate,st-date-normalized=$datefrom - $dateto"); > } > > my ( $build_error, $query, $simple_query, $query_cgi, >diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >index cf36311dfe..aa3fad56ca 100755 >--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >+++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >@@ -219,7 +219,7 @@ subtest 'build_authorities_query_compat() tests' => sub { > }; > > subtest 'build_query tests' => sub { >- plan tests => 58; >+ plan tests => 62; > > my $qb; > >@@ -578,6 +578,38 @@ subtest 'build_query tests' => sub { > is( $limit, '(author:("Dillinger Escaplan")) AND itype:(("BOOK") OR ("CD"))', "Limit formed correctly when no search terms"); > is( $limit_cgi,'&limit=author%3ADillinger%20Escaplan&limit=mc-itype%2Cphr%3ABOOK&limit=mc-itype%2Cphr%3ACD', "Limit CGI formed correctly when no search terms"); > is( $limit_desc,'(author:("Dillinger Escaplan")) AND itype:(("BOOK") OR ("CD"))',"Limit desc formed correctly when no search terms"); >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'], >+ ['acqdate,st-date-normalized= - '] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(barcode:barcode123123) AND date-of-acquisition.raw:[* TO *]', >+ 'If no date all date-of-acquisition are selected' >+ ); >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'], >+ ['acqdate,st-date-normalized=2024-08-01 - '] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(barcode:barcode123123) AND date-of-acquisition.raw:[2024-08-01 TO *]', >+ 'Open start date in date range of an st-date-normalized search is handled properly' >+ ); >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'], >+ ['acqdate,st-date-normalized= - 2024-08-30'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(barcode:barcode123123) AND date-of-acquisition.raw:[* TO 2024-08-30]', >+ 'Open end date in date range of an st-date-normalized search is handled properly' >+ ); >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, ['barcode123123'], ['bc'], >+ ['acqdate,st-date-normalized=2024-08-01 - 2024-08-30'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(barcode:barcode123123) AND date-of-acquisition.raw:[2024-08-01 TO 2024-08-30]', >+ 'Date range in an st-date-normalized search is handled properly' >+ ); > }; > > >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30745
:
134952
|
134953
|
135784
|
135785
|
135966
|
135967
|
157192
|
157194
|
157195
|
157934
|
162855
|
163955
|
170677
|
170678
|
170679
|
170680
|
170681
|
170682
|
170683
|
170684
|
170729
|
170730
|
170731
|
170732
|
170733
|
171002
|
171003
|
171004
|
171005
|
171006
|
173280
|
173943
|
173944
|
173945
|
173946
|
173947
|
174486
|
174487
|
174488
|
174489
|
174490
|
174491