From 63641856dd07880bc20e285e04387c162e22050c Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 25 Oct 2019 13:49:05 +0000 Subject: [PATCH] Bug 23521: (follow-up) Add quotes Not only should terms from facets/limits be grouped, but order should probably matter We build a different facet for "Dillinger Girl" or "Girl Dillinger" The parens are possibly overkill now, but I think it makes it very clear and does not hurt To test: 1 - Follow original plan 2 - Create a new record with 'Girl Dillinger' as author 3 - Search for 'Dill*' 4 - You get all three records (and maybe others that match) 5 - Limit by 'Girl Dillinger' - you get two records 6 - Same for 'Dillinger Girl' 7 - Apply patch 8 - Limits/facets for 'Dillinger Girl' and 'Girl Dillinger' now match a isngle record Signed-off-by: Ere Maijala Signed-off-by: Martin Renvoize --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 2 +- .../Koha/SearchEngine/Elasticsearch/QueryBuilder.t | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 2b8db7e8ae..166121fa11 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -1009,7 +1009,7 @@ sub _fix_limit_special_cases { else { my ( $field, $term ) = $l =~ /^\s*([\w,-]*?):(.*)/; if ( defined($field) && defined($term) ) { - push @new_lim, "$field:($term)"; + push @new_lim, "$field:(\"$term\")"; } else { push @new_lim, $l; diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t index c996f7ccc3..3992e09b18 100644 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t @@ -471,15 +471,15 @@ subtest 'build_query tests' => sub { ( undef, $query ) = $qb->build_query_compat( ['AND'], ['title:"donald duck"'], undef, ['author:Dillinger Escaplan'] ); is( $query->{query}{query_string}{query}, - '(title:"donald duck") AND author:(Dillinger Escaplan)', - "Simplle query with limit's term in parentheses" + '(title:"donald duck") AND author:("Dillinger Escaplan")', + "Simple query with limit term quoted in parentheses" ); ( undef, $query ) = $qb->build_query_compat( ['AND'], ['title:"donald duck"'], undef, ['author:Dillinger Escaplan', 'itype:BOOK'] ); is( $query->{query}{query_string}{query}, - '(title:"donald duck") AND (author:(Dillinger Escaplan)) AND (itype:(BOOK))', - "Simplle query with each limit's term in parentheses" + '(title:"donald duck") AND (author:("Dillinger Escaplan")) AND (itype:("BOOK"))', + "Simple query with each limit's term quoted in parentheses" ); is($query_cgi, 'idx=&q=title%3A%22donald%20duck%22', 'query cgi'); is($query_desc, 'title:"donald duck"', 'query desc ok'); -- 2.39.5