From 2dafd6f7491f64ad8179d00cbcdb3822be57f11f 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 --- 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 416069e1a3..9a87f15347 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -96,6 +96,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 077d5f5a33..c302ec031b 100755 --- a/t/db_dependent/Search.t +++ b/t/db_dependent/Search.t @@ -292,6 +292,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( @@ -930,7 +939,7 @@ sub run_unimarc_search_tests { } subtest 'MARC21 + DOM' => sub { - plan tests => 93; + plan tests => 94; run_marc21_search_tests(); }; @@ -941,7 +950,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'); @@ -970,6 +979,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 ); @@ -982,6 +998,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