From fa53ccb30c257058529b4904493b8ba011b9dc76 Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Wed, 22 Feb 2023 15:45:20 +0100 Subject: [PATCH] Bug 28884: ElasticSearch: Question mark in title search returns no results MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. It happens that question mark (‘?’) is contained in bibliographic data (e.g. in title). 2. It happens that user perform searches with that contain question mark (e.g. searching with a title taken verbatim). 3. In ES queries, in particular in query_string query, question mark has a special meaning – substitutes one character (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-wildcard). Question mark has also special meaning in regexp inside quiery_string (https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_regular_expressions). 4. Ordinary users are not aware of this special function of the question mark and, as a result, receive no results (e.g. while searching for title like "Will libraries survive? : the future of public libraries"). Test plan: ========== 1. Have biblio record with title like 245 10 $a Will libraries survive? : $b the future of public libraries. (= with question mark attached to a word) in Koha instance with ES. 2. Search for: Will libraries survive? the future of public libraries You should get no results. 3. Apply the patch, controll that QueryRegexEscapeOptions is set to Escape. 4. Repeat the search. You should get the record. --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index 53042b4303..6e37ab4829 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -1033,13 +1033,13 @@ sub _query_regex_escape_process { # replaced with a more general parser solution # so that this function is ever only provided with unquoted # query parts - $query =~ s@(?:(?