Browse Source

Bug 24567: Don't strip spaces along with dangling colons

This updates the regex used for removing colons to capture those with space on either side, and remove the colon
while preserving the space

To test:
 1 - Have Koha using ES
 2 - Search for:
    ti:chess AND chess
 3 - You should get a result in sample data, otherwise replace 'chess' with a title in your catalogue
 4 - Search for:
    ti:chess AND kw:chess
 5 - No result
 6 - Enable  DumpTemplateVarsIntranet  and  DumpSearchQueryTemplate
 7 - Repeate search and check page source
 8 - search_query has:
    title:chess ANDchess
 9 - Apply patch
10 - Repeat
11 - Seaerch works!
12 - query is now:
     title:chess AND chess

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>

Bug 24567: (follow-up) Use dollar sign to refer to captures

Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
20.11.x
Nick Clemens 4 years ago
committed by Jonathan Druart
parent
commit
6ce56f1134
  1. 2
      Koha/SearchEngine/Elasticsearch/QueryBuilder.pm
  2. 5
      t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t

2
Koha/SearchEngine/Elasticsearch/QueryBuilder.pm

@ -940,7 +940,7 @@ sub _clean_search_term {
}
# Remove unquoted colons that have whitespace on either side of them
$term =~ s/(\:[:\s]+|[:\s]+:)$lookahead//g;
$term =~ s/((:+)(\s+)|(\s+)(:+))$lookahead/$3$4/g;
$term = $self->_query_regex_escape_process($term);

5
t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t

@ -187,7 +187,7 @@ subtest '_split_query() tests' => sub {
};
subtest '_clean_search_term() tests' => sub {
plan tests => 10;
plan tests => 11;
my $qb;
ok(
@ -221,6 +221,9 @@ subtest '_clean_search_term() tests' => sub {
$res = $qb->_clean_search_term('test {another part');
is($res, 'test another part', 'unbalanced curly brackets replaced correctly');
$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');
};
subtest '_join_queries' => sub {

Loading…
Cancel
Save