From b169b7c71830adf27abd7c9fcceb03737cd9109a Mon Sep 17 00:00:00 2001 From: Petro Vashchuk Date: Mon, 14 Jun 2021 16:32:52 +0300 Subject: [PATCH] Bug 28316: avoid messing up regexes in the search queries This patch ensures that the behavior with QueryRegexEscapeOptions set to values other than "Escape" still will works as expected. It does so by storing the contents of regexes before escaping special characters and then restores the contents of regexes back to how it was before, ensuring that searching with regex is possible. --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 3f27ea2d0a..c7789583e0 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -939,6 +939,16 @@ sub _clean_search_term { } $term = $self->_query_regex_escape_process($term); + # because of _truncate_terms and if QueryAutoTruncate enabled + # we will have any special operators ruined by _truncate_terms: + # for ex. search for "test [6 TO 7]" will be converted to "test* [6* TO* 7]" + # so no reason to keep ranges in QueryAutoTruncate==true case: + my $truncate = C4::Context->preference("QueryAutoTruncate") || 0; + unless($truncate) { + # replace all ranges with any square/curly brackets combinations to temporary substitutions (ex: "{a TO b]"" -> "~~LC~~a TO b~~RS~~") + $term =~ s/(?