Bugzilla – Attachment 87361 Details for
Bug 22295
Elasticsearch - Advanced search should group terms entered in a single input
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22295: Make Elasticsearch query builder group multi-term queries
Bug-22295-Make-Elasticsearch-query-builder-group-m.patch (text/plain), 3.58 KB, created by
Michal Denar
on 2019-04-03 14:35:43 UTC
(
hide
)
Description:
Bug 22295: Make Elasticsearch query builder group multi-term queries
Filename:
MIME Type:
Creator:
Michal Denar
Created:
2019-04-03 14:35:43 UTC
Size:
3.58 KB
patch
obsolete
>From 345789c84cbad59d0f2a51ffb2a443f02364e134 Mon Sep 17 00:00:00 2001 >From: Ere Maijala <ere.maijala@helsinki.fi> >Date: Fri, 8 Mar 2019 13:27:26 +0200 >Subject: [PATCH] Bug 22295: Make Elasticsearch query builder group multi-term > queries > >Test plan: > >1. Do an advanced search for >Title = new >AND >Title = york >2. Verify that the results match an advanced search for: >Title = new york >3. Verify that tests in t/db_dependent/Koha/SearchEngine/Elasticsearch still pass > >Signed-off-by: Michal Denar <black23@gmail.com> > >Signed-off-by: Michal Denar <black23@gmail.com> >--- > Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 1 + > .../Koha/SearchEngine/Elasticsearch/QueryBuilder.t | 32 ++++++++++++++++++++-- > 2 files changed, 31 insertions(+), 2 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index 90331481f2..1560d16ea0 100644 >--- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >+++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >@@ -787,6 +787,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; > "$otor($field$oand)"; > } @queries; > } >diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >index f3e7117a80..03d4d36999 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 => 26; >+ plan tests => 30; > > my $qb; > >@@ -224,6 +224,20 @@ subtest 'build_query tests' => sub { > "query not altered if QueryAutoTruncate disabled" > ); > >+ ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'], ['title'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(title:(donald duck))', >+ 'multiple words in a query term are enclosed in parenthesis' >+ ); >+ >+ ( undef, $query ) = $qb->build_query_compat( ['AND'], ['donald duck', 'disney'], ['title', 'author'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(title:(donald duck)) AND (author:disney)', >+ 'multiple query terms are enclosed in parenthesis while a single one is not' >+ ); >+ > t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' ); > > ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] ); >@@ -324,7 +338,21 @@ subtest 'build_query tests' => sub { > is( > $query->{query}{query_string}{query}, > '(title:"donald duck")', >- "query of specific field is not truncated when surrouned by quotes" >+ "query of specific field is not truncated when surrounded by quotes" >+ ); >+ >+ ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'], ['title'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(title:(donald* duck*))', >+ 'words of a multi-word term are properly truncated' >+ ); >+ >+ ( undef, $query ) = $qb->build_query_compat( ['AND'], ['donald duck', 'disney'], ['title', 'author'] ); >+ is( >+ $query->{query}{query_string}{query}, >+ '(title:(donald* duck*)) AND (author:disney*)', >+ 'words of a multi-word term and single-word term are properly truncated' > ); > > ( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 1 } ); >-- >2.11.0
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 22295
:
86370
|
87359
|
87360
|
87361
|
87368