Bug 22046: Simplify and unify the code for get_matches

To test:
1 - Stage some records for import
2 - Manage the records
3 - Use several different matching rules and note the results
4 - Apply patch
5 - Try several matching rules again and note the results have not
changed
6 - Try under both search engines (Zebra and ES)

Signed-off-by: Liz Rea <wizzyrea@gmail.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Nick Clemens 2018-12-24 12:52:53 +00:00 committed by root
parent cbacf68d7f
commit 53545ba739

View file

@ -675,21 +675,14 @@ sub get_matches {
warn "search failed ($query) $error";
}
else {
if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
foreach my $matched ( @{$searchresults} ) {
my ( $biblionumber_tag, $biblionumber_subfield ) = C4::Biblio::GetMarcFromKohaField( "biblio.biblionumber", $marcframework_used );
my $id = ( $biblionumber_tag > 10 ) ?
$matched->field($biblionumber_tag)->subfield($biblionumber_subfield) :
$matched->field($biblionumber_tag)->data();
$matches->{$id}->{score} += $matchpoint->{score};
$matches->{$id}->{record} = $matched;
}
}
else {
foreach my $matched ( @{$searchresults} ) {
$matches->{$matched}->{score} += $matchpoint->{'score'};
$matches->{$matched}->{record} = $matched;
}
foreach my $matched ( @{$searchresults} ) {
my $target_record = C4::Search::new_record_from_zebra( 'biblioserver', $matched );
my ( $biblionumber_tag, $biblionumber_subfield ) = C4::Biblio::GetMarcFromKohaField( "biblio.biblionumber", $marcframework_used );
my $id = ( $biblionumber_tag > 10 ) ?
$target_record->field($biblionumber_tag)->subfield($biblionumber_subfield) :
$target_record->field($biblionumber_tag)->data();
$matches->{$id}->{score} += $matchpoint->{score};
$matches->{$id}->{record} = $target_record;
}
}
@ -741,10 +734,8 @@ sub get_matches {
};
foreach my $id ( keys %$matches ) {
my $target_record = C4::Search::new_record_from_zebra( 'biblioserver', $matches->{$id}->{record} );
my $result = C4::Biblio::TransformMarcToKoha( $target_record, $marcframework_used );
push @results, {
record_id => $result->{biblionumber},
record_id => $id,
score => $matches->{$id}->{score}
};
}