Browse Source

Bug 27928: FindDuplicate should 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

Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.05.x
Nick Clemens 2 years ago
committed by Jonathan Druart
parent
commit
93a297a7a2
  1. 3
      C4/Search.pm
  2. 45
      t/db_dependent/Search.t

3
C4/Search.pm

@ -116,7 +116,8 @@ sub FindDuplicate {
}
}
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}) {

45
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";
}
};

Loading…
Cancel
Save