From a0aa2ff4afda2d8aab2aa06eec4f5e045bb2d9b8 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 24 Feb 2023 14:04:34 +0000 Subject: [PATCH] Bug 31471: Send multiple ISBN with 'OR' for FindDuplicate When a record has multiple ISBNs the database stores them seperated by a pipe Zebra interprets a string like "isbn:1600213510 | 9781600213519" as an 'OR' search, but for Elasticsearch we need to explicitly send "OR" - and Zebra support this as well To test: 1 - Make sure you are using Elasticsearch 2 - Cataloging->Add a new record from Z3950 3 - Choose target: LOC 4 - Search for: Control number: 14455023 5 - Import and save 6 - Search for the record again 7 - Import and save - duplicate check isn't been triggered 8 - Apply patch 9 - restart_all 10 - repeat 2-7 11 - this time you should get a duplicate notification 12 - Sitch SearchEngine syspref to 'Zebra' 13 - repeat 2-7 14 - Ensure you still get duplicate notification Signed-off-by: Michaela Sieber Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 2dafd6f7491f64ad8179d00cbcdb3822be57f11f) Signed-off-by: Jacob O'Mara (cherry picked from commit 47ad3dd1b284c74a7b1850e45b3fb3d0e72f677e) Signed-off-by: Lucas Gass (cherry picked from commit 26d9092de48164418c103e79abcb7db81c8be5e7) Signed-off-by: Arthur Suzuki --- C4/Search.pm | 1 + t/db_dependent/Search.t | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 8b19d1ffe4..0c4f7baa44 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -93,6 +93,7 @@ sub FindDuplicate { if ( $result->{isbn} ) { $result->{isbn} =~ s/\(.*$//; $result->{isbn} =~ s/\s+$//; + $result->{isbn} =~ s/\|/OR/; $query = "isbn:$result->{isbn}"; } else { diff --git a/t/db_dependent/Search.t b/t/db_dependent/Search.t index a01ccfe3e2..6424ed4eac 100755 --- a/t/db_dependent/Search.t +++ b/t/db_dependent/Search.t @@ -291,6 +291,15 @@ sub run_marc21_search_tests { ($biblionumber,undef,$title) = FindDuplicate($record); is($biblionumber, 51, 'Found duplicate with ISBN'); + $record = MARC::Record->new; + $record->add_fields( + [ '020', ' ', ' ', a => '0465039146' ], + [ '020', ' ', ' ', a => '9780465039142' ], + [ '245', '0', '0', a => 'Doesnt matter, searching isbn /' ] + ); + ($biblionumber,undef,$title) = FindDuplicate($record); + is($biblionumber, 48, 'Found duplicate with ISBN when two ISBNs in record'); + $record = MARC::Record->new; $record->add_fields( @@ -916,7 +925,7 @@ sub run_unimarc_search_tests { } subtest 'MARC21 + DOM' => sub { - plan tests => 93; + plan tests => 94; run_marc21_search_tests(); }; @@ -927,7 +936,7 @@ subtest 'UNIMARC + DOM' => sub { subtest 'FindDuplicate' => sub { - plan tests => 6; + plan tests => 8; Koha::Caches->get_instance('config')->flush_all; t::lib::Mocks::mock_preference('marcflavour', 'MARC21' ); mock_GetMarcSubfieldStructure('MARC21'); @@ -956,6 +965,13 @@ subtest 'FindDuplicate' => sub { $record_3->add_fields( [ '245', '0', '0', a => 'Frog and toad all year /' ] ); + my $record_4 = MARC::Record->new; + $record_4 ->add_fields( + [ '020', ' ', ' ', a => '9780307744432' ], + [ '020', ' ', ' ', a => '0307744434' ], + [ '100', '0', '0', a => 'Morgenstern, Erin' ], + [ '245', '0', '0', a => 'The night circus /' ] + ); foreach my $engine ('Zebra','Elasticsearch'){ t::lib::Mocks::mock_preference('searchEngine', $engine ); @@ -968,6 +984,9 @@ subtest 'FindDuplicate' => sub { warning_is { C4::Search::FindDuplicate($record_3);} q/ti,ext:"Frog and toad all year \/"/,"Term correctly formed and passed to $engine"; + + warning_is { C4::Search::FindDuplicate($record_4);} + q/isbn:9780307744432 OR 0307744434/,"Term correctly formed and passed to $engine"; } }; -- 2.39.5