Bugzilla – Attachment 121435 Details for
Bug 28316
Fix ES crashes related to various punctuation characters
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 28316: screen square and curly brackets in the search query
Bug-28316-screen-square-and-curly-brackets-in-the-.patch (text/plain), 3.93 KB, created by
Peter Vashchuk
on 2021-05-26 14:38:25 UTC
(
hide
)
Description:
Bug 28316: screen square and curly brackets in the search query
Filename:
MIME Type:
Creator:
Peter Vashchuk
Created:
2021-05-26 14:38:25 UTC
Size:
3.93 KB
patch
obsolete
>From 754a513095089bebff1378ee551dab48a229e12a Mon Sep 17 00:00:00 2001 >From: Petro Vashchuk <stalkernoid@gmail.com> >Date: Tue, 25 May 2021 14:36:20 +0300 >Subject: [PATCH] Bug 28316: screen square and curly brackets in the search > query > >This patch screens all 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]). >Previously, there was old time fix for curly brackets that replaced them >with quotes which made curly brackets range functionality not working, >that code was also removed with this patch Also this patch adds tests >for this behavior. > >To reproduce: >1) with ES enabled, search for a book with tittle like "test [test]", >which will result in error. >2) apply the patch. >3) search for that book again, which should work now. >4) run test QueryBuilder.t to make sure that it runs successfully. >--- > Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 8 +++++++- > t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t | 13 ++++++++----- > 2 files changed, 15 insertions(+), 6 deletions(-) > >diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm >index a39931ab0b..1bff8a3cba 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; >@@ -944,6 +943,13 @@ sub _clean_search_term { > $term =~ s/(\s+)(:+)$lookahead/$1/g; > $term =~ s/^://; > >+ # replace all ranges with any square/curly brackets combinations to temporary substitutions (ex: "{a TO b]"" -> "~~LC~~a TO b~~RS~~") >+ $term =~ s/(\{|\[)([^\s\[\]\{\}]+ TO [^\s\[\]\{\}]+)(\}|\])/'~~L'.($1 eq '[' ? 'S':'C').'~~'.$2.'~~R'.($3 eq ']' ? 'S':'C').'~~'/ge; >+ # screen all brackets with backslash >+ $term =~ s/([\{\}\[\]])/\\$1/g; >+ # restore temporary weird substitutions back to normal brackets >+ $term =~ s/~~L(C|S)~~([^\s\[\]\{\}]+ TO [^\s\[\]\{\}]+)~~R(C|S)~~/($1 eq 'S' ? '[':'{').$2.($3 eq 'S' ? ']':'}')/ge; >+ > $term = $self->_query_regex_escape_process($term); > > return $term; >diff --git a/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t b/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >index b2ce6f4319..7175f63743 100755 >--- a/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >+++ b/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t >@@ -187,7 +187,7 @@ subtest '_split_query() tests' => sub { > }; > > subtest '_clean_search_term() tests' => sub { >- plan tests => 12; >+ plan tests => 13; > > my $qb; > ok( >@@ -216,11 +216,14 @@ subtest '_clean_search_term() tests' => sub { > $res = $qb->_clean_search_term('test "another : query"'); > is($res, 'test "another : query"', 'quoted dangling colon not removed'); > >- $res = $qb->_clean_search_term('test {another part}'); >- is($res, 'test "another part"', 'curly brackets replaced correctly'); >+ $res = $qb->_clean_search_term('test [123 TO 345]'); >+ is($res, 'test [123 TO 345]', 'keep inculsive range untouched'); >+ >+ $res = $qb->_clean_search_term('test [test TO TEST} [and] {123 TO 456]'); >+ is($res, 'test [test TO TEST} \[and\] {123 TO 456]', 'keep exclusive range untouched'); > >- $res = $qb->_clean_search_term('test {another part'); >- is($res, 'test another part', 'unbalanced curly brackets replaced correctly'); >+ $res = $qb->_clean_search_term('test[]test TO TEST] [ {123 to 345}}'); >+ is($res, 'test\[\]test TO TEST\] \[ \{123 to 345\}\}', 'screen all square and curly brackets'); > > $res = $qb->_clean_search_term('ti:test AND kw:test'); > is($res, 'title:test AND test', 'ti converted to title, kw converted to empty string, dangling colon removed with space preserved'); >-- >2.31.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 28316
:
121435
|
121443
|
121561
|
121562
|
121751
|
121752
|
121753
|
121754
|
121755
|
121756
|
121837
|
121838
|
121839
|
121840
|
121841
|
121842
|
121975
|
121976
|
121977
|
121978
|
121979
|
121980
|
122103
|
122104
|
122105
|
122106
|
122107
|
122108
|
122201
|
122202
|
122203
|
122204
|
122205
|
122206
|
122801
|
122802
|
122803
|
122804
|
122805
|
122806
|
123601
|
123602
|
123603
|
123604
|
123605
|
123606
|
124372
|
124373
|
124374
|
124375
|
124376
|
124377
|
124378
|
124560
|
124561
|
124562
|
124563
|
124564
|
124565
|
124566
|
124709
|
124710
|
124711
|
124712
|
124713
|
124714
|
124715