From adac91502fe208a827cec71055bce9d5434c70dd Mon Sep 17 00:00:00 2001 From: Fridolin Somers Date: Thu, 18 Feb 2021 15:37:15 +0100 Subject: [PATCH] Bug 27724: Use lenient also in Elasticsearch authorities search MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit In Elasticsearch, query for biblios uses lenient=true. This is also needed for authorities search. In case a search field is defined as type numeric. Test plan : 1) Use Elasticsearch searchengine 2) Define a search field 'local-number' as type 'Number' 3) Be sure to us 'local-number' in autorities mapping 4) Rebuild autorities 5) Performe a search for autorities with 'Search entire record' and 'contains' with term '123' => Without patch you get error : [query_shard_exception] Can only use prefix queries on keyword and text fields - not on [local-number] which is of type [integer] Signed-off-by: Séverine QUEUNE Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart (cherry picked from commit 32f2026c1b6d5b97e6594020383940063d2b6fca) Signed-off-by: Fridolin Somers --- .../Elasticsearch/QueryBuilder.pm | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index eed466049b..a39931ab0b 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -449,23 +449,18 @@ sub build_authorities_query { ); } my $query = $self->_join_queries( @tokens ); - + my $query_string = { + query => $query, + lenient => JSON::true, + analyze_wildcard => JSON::true, + }; if ($wh) { - push @query_parts, { query_string => { - default_field => $wh, - analyze_wildcard => JSON::true, - query => $query - } }; + $query_string->{default_field} = $wh; } else { - push @query_parts, { - query_string => { - analyze_wildcard => JSON::true, - query => $query, - fields => $self->_search_fields(), - } - }; + $query_string->{fields} = $self->_search_fields(); } + push @query_parts, { query_string => $query_string }; } } -- 2.39.5