From 1106c31bbdf9ce7edfb734cb9eab55535cad4f54 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 11 Mar 2021 13:33:43 +0000 Subject: [PATCH] Bug 27928: FindDuplicate shuold use simple_search_compat This patch switches from calling SimpleSearch directly to using the compat method so that Elastic is used when it is the chosen search engine To test: 1 - Set SearchEngine syspref to 'Zebra' 2 - Add a suggestion with an existing title, e.g.: 'E street shuffle' 3 - Confirm you get a duplication warning 4 - Change SearchEngine to ES 5 - Repeat get same warning 6 - sudo koha-zebra --stop 'ps aux | grep zebra' to confirm they are stoped 'sudo pkill -9 zebra' if they arent; 7 - Repeat suggestion - no duplication warning (because zebra returns nothing) 8 - Delete the suggestion 9 - Apply patches 10 - Restart all the things, stop zebra 11 - Repeat suggestion 12 - Successful warning from ES 13 - prove -v t/db_dependent/Search.t --- C4/Search.pm | 5 +++-- t/db_dependent/Search.t | 45 ++++++++++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/C4/Search.pm b/C4/Search.pm index 4413211849..c2c8d4ecea 100644 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -115,8 +115,9 @@ sub FindDuplicate { $query .= " $op $authorindex:\"$result->{author}\""; } } - - my ( $error, $searchresults, undef ) = SimpleSearch($query); # FIXME :: hardcoded ! + + my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); + my ( $error, $searchresults, undef ) = $searcher->simple_search_compat($query,0,50); my @results; if (!defined $error) { foreach my $possible_duplicate_record (@{$searchresults}) { diff --git a/t/db_dependent/Search.t b/t/db_dependent/Search.t index 3b4e6d38dc..10c44c9592 100755 --- a/t/db_dependent/Search.t +++ b/t/db_dependent/Search.t @@ -923,37 +923,48 @@ subtest 'UNIMARC + DOM' => sub { subtest 'FindDuplicate' => sub { - plan tests => 3; + plan tests => 6; Koha::Caches->get_instance('config')->flush_all; t::lib::Mocks::mock_preference('marcflavour', 'marc21' ); mock_GetMarcSubfieldStructure('marc21'); - my $searcher = Test::MockModule->new('C4::Search'); - $searcher->mock('SimpleSearch', sub { + my $z_searcher = Test::MockModule->new('C4::Search'); + $z_searcher->mock('SimpleSearch', sub { + warn shift @_; + return 1; + }); + my $e_searcher = Test::MockModule->new('Koha::SearchEngine::Elasticsearch::Search'); + $e_searcher->mock('simple_search_compat', sub { + shift @_; warn shift @_; return 1; }); - my $record = MARC::Record->new; - $record->add_fields( + my $record_1 = MARC::Record->new; + $record_1 ->add_fields( [ '100', '0', '0', a => 'Morgenstern, Erin' ], [ '245', '0', '0', a => 'The night circus /' ] ); - warning_is { C4::Search::FindDuplicate($record);} - q/ti,ext:"The night circus \/" and au,ext:"Morgenstern, Erin"/,"Term correctly formed"; - - $record = MARC::Record->new; - $record->add_fields( + my $record_2 = MARC::Record->new; + $record_2 ->add_fields( [ '245', '0', '0', a => 'The book of nothing /' ] ); - warning_is { C4::Search::FindDuplicate($record);} - q/ti,ext:"The book of nothing \/"/,"Term correctly formed"; - - $record = MARC::Record->new; - $record->add_fields( + my $record_3 = MARC::Record->new; + $record_3->add_fields( [ '245', '0', '0', a => 'Frog and toad all year /' ] ); - warning_is { C4::Search::FindDuplicate($record);} - q/ti,ext:"Frog and toad all year \/"/,"Term correctly formed"; + + foreach my $engine ('Zebra','Elasticsearch'){ + t::lib::Mocks::mock_preference('searchEngine', $engine ); + + warning_is { C4::Search::FindDuplicate($record_1);} + q/ti,ext:"The night circus \/" and au,ext:"Morgenstern, Erin"/,"Term correctly formed and passed to $engine"; + + warning_is { C4::Search::FindDuplicate($record_2);} + q/ti,ext:"The book of nothing \/"/,"Term correctly formed and passed to $engine"; + + warning_is { C4::Search::FindDuplicate($record_3);} + q/ti,ext:"Frog and toad all year \/"/,"Term correctly formed and passed to $engine"; + } }; -- 2.11.0