From 0083f96bc9238148a67a58512331144e28b08c94 Mon Sep 17 00:00:00 2001 From: Petro Vashchuk Date: Fri, 18 Jun 2021 10:44:56 +0300 Subject: [PATCH] Bug 28316: escape exclamation signs in the query Currently having exclamation sign at the end of the query makes ES search fail, and when you try to search for a book that has exclamation sign in the tittle (something like "Words! words") won't show results correctly as it tries to negate everything that is after exclamation sign, making it impossible to search for books that have in in the title This patch escapes exclamation signs if it's at the end of the query or has a space after it, resolving both of the issues listed above. To reproduce: 1) with ES enabled, search for the book with title that contains exclamation sight at the end, like "book!", this search should result in error. 2) do another search, but this time find/prepare beforehand book with a title that has exclamation sign with a space after it, e.g "exclamation! sign", it shouldn't find it as ES treats everything after that exclamation sign as negation. 2) apply the patch. 3) perform searches from the steep one and two again. Search from step one should no longer fail, while search from the step two should find that book. Signed-off-by: Victor Grousset/tuxayo Signed-off-by: Alex Buckley Signed-off-by: Martin Renvoize Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 4621199c53..6f097ce89b 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -951,6 +951,9 @@ sub _clean_search_term { # and correctly ignore unevenly backslashed: $term =~ s/((?