From 8f6634cdbb711b94a82a6afb4945a4ac1ff2482b Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Tue, 2 Jan 2018 16:27:18 +0100 Subject: [PATCH] Bug 19905 - Don't append wildcard to query terms Appending '*' to query terms makes Elasticsearch skip search analysis. This will for example cause issues with search links in biblio details for values other than a just single term, since the indexed value has been tokenized. How to test: 1) Find a biblio with a field value containing word boundaries and/or punctuation marks. For example: "au:Author, Name". 2) Perform a search using this query, this should not produce any results. 3) Apply patch. 4) Search using the same query again, it should now produce the expected results. --- Koha/SearchEngine/Elasticsearch/QueryBuilder.pm | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm index a021a0cb52..11382a5089 100644 --- a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm +++ b/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm @@ -801,14 +801,7 @@ sub _truncate_terms { my @tokens = split /((?:[\w-]+:)?"[^"]+"|\s+)/, $query; # Filter out empty tokens - my @words = grep { $_ !~ /^\s*$/ } @tokens; - - # Append '*' to words if needed, ie. if it's not surrounded by quotes, not - # terminated by '*' and not a keyword - my @terms = map { - my $w = $_; - (/"$/ or /\*$/ or grep {lc($w) eq $_} qw/and or not/) ? $_ : "$_*"; - } @words; + my @terms = grep { $_ !~ /^\s*$/ } @tokens; return join ' ', @terms; } -- 2.11.0