Bugzilla – Attachment 88758 Details for
Bug 22524
Elasticsearch - Date range in advanced search
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22524: Fix publication date search with Elasticsearch
Bug-22524-Fix-publication-date-search-with-Elastic.patch (text/plain), 4.77 KB, created by
Ere Maijala
on 2019-04-25 12:00:18 UTC
(
hide
)
Description:
Bug 22524: Fix publication date search with Elasticsearch
Filename:
MIME Type:
Creator:
Ere Maijala
Created:
2019-04-25 12:00:18 UTC
Size:
4.77 KB
patch
obsolete
>From e5f8e41cb0d47d926ef6c6ae6f923cc60aff7514 Mon Sep 17 00:00:00 2001 >From: Ere Maijala <ere.maijala@helsinki.fi> >Date: Tue, 16 Apr 2019 16:26:40 +0300 >Subject: [PATCH] Bug 22524: Fix publication date search with Elasticsearch > >Also fixes the mappings.yaml to use correct field name (left over issue from bug 19575), so reset mappings and reindex before testing. > >Test plan: >1. Reset mappings and reindex biblios. >2. Check that tests in t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t pass. >3. Try that all of the following year range type work in publication date search in advanced search: >yyyy >yyyy-yyyy >-yyyy >yyyy- >--- > .../Elasticsearch/QueryBuilder.pm | 12 +++++-- > .../searchengine/elasticsearch/mappings.yaml | 4 +-- > .../SearchEngine/Elasticsearch/QueryBuilder.t | 31 ++++++++++++++++++- > 3 files changed, 42 insertions(+), 5 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index 084d5ad3db..d18db31462 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -622,7 +622,7 @@ sub _convert_index_fields { > my ( $self, @indexes ) = @_; > > my %index_type_convert = >- ( __default => undef, phr => 'phrase', rtrn => 'right-truncate' ); >+ ( __default => undef, phr => 'phrase', rtrn => 'right-truncate', 'st-year' => 'st-year' ); > > # Convert according to our table, drop anything that doesn't convert. > # If a field starts with mc- we save it as it's used (and removed) later >@@ -729,6 +729,14 @@ sub _modify_string_by_type { > > $str .= '*' if $type eq 'right-truncate'; > $str = '"' . $str . '"' if $type eq 'phrase'; >+ if ($type eq 'st-year') { >+ my ($from, $until); >+ if ($str =~ /^(.*)-(.*)$/) { >+ $from = $1 || '*'; >+ $until = $2 || '*'; >+ $str = "[$from TO $until]"; >+ } >+ } > return $str; > } > >@@ -801,7 +809,7 @@ sub _create_query_string { > my $field = $_->{field} ? $_->{field} . ':' : ''; > > my $oand = $self->_modify_string_by_type(%$_); >- $oand = "($oand)" if $field && scalar(split(/\s+/, $oand)) > 1; >+ $oand = "($oand)" if $field && scalar(split(/\s+/, $oand)) > 1 && $_->{type} ne 'st-year'; > "$otor($field$oand)"; > } @queries; > } >diff --git a/admin/searchengine/elasticsearch/mappings.yaml b/admin/searchengine/elasticsearch/mappings.yaml >index a546c341e6..e2b17b25f8 100644 >--- a/admin/searchengine/elasticsearch/mappings.yaml >+++ b/admin/searchengine/elasticsearch/mappings.yaml >@@ -3167,8 +3167,8 @@ biblios: > sort: ~ > suggestible: '' > type: '' >- pubdate: >- label: pubdate >+ date-of-publication: >+ label: date-of-publication > mappings: > - facet: '' > marc_field: 008_/7-10 >diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >index df2f323383..8746ff6a69 100644 >--- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >+++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >@@ -169,7 +169,7 @@ subtest 'build_authorities_query_compat() tests' => sub { > }; > > subtest 'build_query tests' => sub { >- plan tests => 33; >+ plan tests => 37; > > my $qb; > >@@ -243,6 +243,35 @@ subtest 'build_query tests' => sub { > is($query_cgi, 'idx=ti&q=%22donald%20duck%22&idx=au&q=walt%20disney', 'query cgi ok for multiterm query'); > is($query_desc, '(title:("donald duck")) (author:(walt disney))', 'query desc ok for multiterm query'); > >+ ( undef, $query ) = $qb->build_query_compat( undef, ['2019'], ['yr,st-year'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(date-of-publication:2019)', >+ 'Year in an st-year search is handled properly' >+ ); >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, ['2018-2019'], ['yr,st-year'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(date-of-publication:[2018 TO 2019])', >+ 'Year range in an st-year search is handled properly' >+ ); >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, ['-2019'], ['yr,st-year'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(date-of-publication:[* TO 2019])', >+ 'Open start year in year range of an st-year search is handled properly' >+ ); >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, ['2019-'], ['yr,st-year'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(date-of-publication:[2019 TO *])', >+ 'Open end year in year range of an st-year search is handled properly' >+ ); >+ >+ # Enable auto-truncation > t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' ); > > ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] ); >-- >2.17.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 22524
:
88063
|
88758
|
88998
|
88999
|
89000
|
89152
|
89153
|
91562
|
91563