View | Details | Raw Unified | Return to bug 28316
Collapse All | Expand All

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-1 / +7 lines)
Lines 930-936 sub _clean_search_term { Link Here
930
    $term =~ s/=/:/g;
930
    $term =~ s/=/:/g;
931
931
932
    $term = $self->_convert_index_strings_freeform($term);
932
    $term = $self->_convert_index_strings_freeform($term);
933
    $term =~ s/[{}]/"/g;
934
933
935
    # Remove unbalanced quotes
934
    # Remove unbalanced quotes
936
    my $unquoted = $term;
935
    my $unquoted = $term;
Lines 944-949 sub _clean_search_term { Link Here
944
    $term =~ s/(\s+)(:+)$lookahead/$1/g;
943
    $term =~ s/(\s+)(:+)$lookahead/$1/g;
945
    $term =~ s/^://;
944
    $term =~ s/^://;
946
945
946
    # replace all ranges with any square/curly brackets combinations to temporary substitutions (ex: "{a TO b]"" -> "~~LC~~a TO b~~RS~~")
947
    $term =~ s/(\{|\[)([^\s\[\]\{\}]+ TO [^\s\[\]\{\}]+)(\}|\])/'~~L'.($1 eq '[' ? 'S':'C').'~~'.$2.'~~R'.($3 eq ']' ? 'S':'C').'~~'/ge;
948
    # screen all brackets with backslash
949
    $term =~ s/([\{\}\[\]])/\\$1/g;
950
    # restore temporary weird substitutions back to normal brackets
951
    $term =~ s/~~L(C|S)~~([^\s\[\]\{\}]+ TO [^\s\[\]\{\}]+)~~R(C|S)~~/($1 eq 'S' ? '[':'{').$2.($3 eq 'S' ? ']':'}')/ge;
952
947
    $term = $self->_query_regex_escape_process($term);
953
    $term = $self->_query_regex_escape_process($term);
948
954
949
    return $term;
955
    return $term;
(-)a/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-6 / +8 lines)
Lines 187-193 subtest '_split_query() tests' => sub { Link Here
187
};
187
};
188
188
189
subtest '_clean_search_term() tests' => sub {
189
subtest '_clean_search_term() tests' => sub {
190
    plan tests => 12;
190
    plan tests => 13;
191
191
192
    my $qb;
192
    my $qb;
193
    ok(
193
    ok(
Lines 216-226 subtest '_clean_search_term() tests' => sub { Link Here
216
    $res = $qb->_clean_search_term('test "another : query"');
216
    $res = $qb->_clean_search_term('test "another : query"');
217
    is($res, 'test "another : query"', 'quoted dangling colon not removed');
217
    is($res, 'test "another : query"', 'quoted dangling colon not removed');
218
218
219
    $res = $qb->_clean_search_term('test {another part}');
219
    $res = $qb->_clean_search_term('test [123 TO 345]');
220
    is($res, 'test "another part"', 'curly brackets replaced correctly');
220
    is($res, 'test [123 TO 345]', 'keep inculsive range untouched');
221
222
    $res = $qb->_clean_search_term('test [test TO TEST} [and] {123 TO 456]');
223
    is($res, 'test [test TO TEST} \[and\] {123 TO 456]', 'keep exclusive range untouched');
221
224
222
    $res = $qb->_clean_search_term('test {another part');
225
    $res = $qb->_clean_search_term('test[]test TO TEST] [ {123 to 345}}');
223
    is($res, 'test  another part', 'unbalanced curly brackets replaced correctly');
226
    is($res, 'test\[\]test TO TEST\] \[ \{123 to 345\}\}', 'screen all square and curly brackets');
224
227
225
    $res = $qb->_clean_search_term('ti:test AND kw:test');
228
    $res = $qb->_clean_search_term('ti:test AND kw:test');
226
    is($res, 'title:test AND test', 'ti converted to title, kw converted to empty string, dangling colon removed with space preserved');
229
    is($res, 'title:test AND test', 'ti converted to title, kw converted to empty string, dangling colon removed with space preserved');
227
- 

Return to bug 28316