From 93f875f061502db1ce9cc1d8bba42d9253f4cdfc Mon Sep 17 00:00:00 2001 From: Kevin Carnes Date: Tue, 22 Feb 2022 14:29:15 +0100 Subject: [PATCH] When a query with "OR" is combined with a limit in Elasticsearch, the precedence is not preserved and the results are not correct. To test: 1) Set SearchEngine to Elasticsearch 2) Index records in Elasticsearch 3) Do an advanced search 4) Select More options 5) Enter a value for the first Keyword (e.g. Title) 6) Change "and" before the second Keyword to "or" 7) Enter another value for the second Keyword (e.g. Prose) 8) Limit the search (e.g. Item type Books) 9) Do the search 10) Observe that records with the first keyword are not in the results 11) Apply the patch 12) Repeats the search 13) Observe that results with both keywords are in the results 14) Sign off https://bugs.koha-community.org/show_bug.cgi?id=30152 --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 3e2cb1b784..b2ef8aa8d9 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -306,9 +306,7 @@ sub build_query_compat { # them into a structured ES query itself. Maybe later, though that'd be # more robust. $search_param_query_str = join( ' ', $self->_create_query_string(@search_params) ); - $query_str = join( ' AND ', - $search_param_query_str || (), - $self->_join_queries( $self->_convert_index_strings(@$limits) ) || () ); + $query_str = join( ' AND ', map { "($_)" } grep { $_ } ( $search_param_query_str, $self->_join_queries( $self->_convert_index_strings(@$limits) ) ) ); # If there's no query on the left, let's remove the junk left behind $query_str =~ s/^ AND //; -- 2.17.1