From a819ae07a60cd52f44b9dc5785dd28df79a6a6df Mon Sep 17 00:00:00 2001 From: =?utf8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Tue, 24 Nov 2020 19:19:04 +0200 Subject: [PATCH] Bug 11175: Search using double quotes to support Elasticsearch With Elasticsearch if you would use the search string here without the change to double quotes, i.e. (rcn='1234' AND cni='FI-XXX') OR rcn='FI-XXX 1234' then the search would somehow manage to return a record with 001 = 1234 and 003 = FI-XXX. Using double quotes prevents that. Also using parenthesis around the latter part of the OR seems to work: (rcn='1234' AND cni='FI-XXX') OR (rcn='FI-XXX 1234') Signed-off-by: Pasi Kallinen Signed-off-by: Martin Renvoize Signed-off-by: Andrew Nugged Signed-off-by: Marcel de Rooy Signed-off-by: Jonathan Druart --- Koha/Util/Search.pm | 6 +++--- t/Koha/Util/Search.t | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Koha/Util/Search.pm b/Koha/Util/Search.pm index ddf0587cdd..0228183e35 100644 --- a/Koha/Util/Search.pm +++ b/Koha/Util/Search.pm @@ -45,11 +45,11 @@ sub get_component_part_query { if (!defined($pf003)) { # search for 773$w='Host001' - $searchstr = "rcn='".$pf001->data()."'"; + $searchstr = "rcn=\"".$pf001->data()."\""; } else { # search for (773$w='Host001' and 003='Host003') or 773$w='Host003 Host001') - $searchstr = "(rcn='".$pf001->data()."' AND cni='".$pf003->data()."')"; - $searchstr .= " OR rcn='".$pf003->data()." ".$pf001->data()."'"; + $searchstr = "(rcn=\"".$pf001->data()."\" AND cni=\"".$pf003->data()."\")"; + $searchstr .= " OR rcn=\"".$pf003->data()." ".$pf001->data()."\""; } } } diff --git a/t/Koha/Util/Search.t b/t/Koha/Util/Search.t index c56b9404e2..e5cde2900b 100755 --- a/t/Koha/Util/Search.t +++ b/t/Koha/Util/Search.t @@ -38,5 +38,5 @@ subtest 'get_component_part_query' => sub { $record->append_fields($marc_001_field); ModBiblioMarc($record, $biblionumber); - is(Koha::Util::Search::get_component_part_query($biblionumber), "rcn='$biblionumber'"); + is(Koha::Util::Search::get_component_part_query($biblionumber), "rcn=\"$biblionumber\""); }; -- 2.39.5