From dc2fc242cb06f994f1719fbe9810d9f68e908577 Mon Sep 17 00:00:00 2001 From: Petro Vashchuk Date: Mon, 14 Jun 2021 16:39:13 +0300 Subject: [PATCH] Bug 28316: escape brackets in the search query This patch screens square and curly brackets which have no special language meaning, while keeping ranges as they are, allowing ES to search for biblios with titles that contain square and curly brackets and at the same time allows the use of range searches ([1990 TO 2000]). To reproduce: 1) using ES, search for the book with title that contains square and/or curly brackets, like "book [second edition]", which will result in error. 2) apply the patch. 3) search for that book again, ensure that it works now. 4) additionally perform a search using range, for example: "[1999 TO 2020]", ensure that it works correctly too. --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 3a80b37797..6d26adff4c 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -930,7 +930,6 @@ sub _clean_search_term { $term =~ s/=/:/g; $term = $self->_convert_index_strings_freeform($term); - $term =~ s/[{}]/"/g; # Remove unbalanced quotes my $unquoted = $term; @@ -952,6 +951,9 @@ sub _clean_search_term { # and correctly ignore unevenly backslashed: $term =~ s/((?