|
Lines 619-625
sub get_matches {
Link Here
|
| 619 |
my $self = shift; |
619 |
my $self = shift; |
| 620 |
my ($source_record, $max_matches) = @_; |
620 |
my ($source_record, $max_matches) = @_; |
| 621 |
|
621 |
|
| 622 |
my %matches = (); |
622 |
my $matches = {}; |
|
|
623 |
my $marcframework_used = ''; # use the default framework |
| 623 |
|
624 |
|
| 624 |
my $QParser; |
625 |
my $QParser; |
| 625 |
$QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser')); |
626 |
$QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser')); |
|
Lines 665-670
sub get_matches {
Link Here
|
| 665 |
my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); |
666 |
my $searcher = Koha::SearchEngine::Search->new({index => $Koha::SearchEngine::BIBLIOS_INDEX}); |
| 666 |
( $error, $searchresults, $total_hits ) = |
667 |
( $error, $searchresults, $total_hits ) = |
| 667 |
$searcher->simple_search_compat( $query, 0, $max_matches, undef, skip_normalize => 1 ); |
668 |
$searcher->simple_search_compat( $query, 0, $max_matches, undef, skip_normalize => 1 ); |
|
|
669 |
|
| 670 |
if ( defined $error ) { |
| 671 |
warn "search failed ($query) $error"; |
| 672 |
} |
| 673 |
else { |
| 674 |
if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) { |
| 675 |
foreach my $matched ( @{$searchresults} ) { |
| 676 |
my ( $biblionumber_tag, $biblionumber_subfield ) = C4::Biblio::GetMarcFromKohaField( "biblio.biblionumber", $marcframework_used ); |
| 677 |
my $id = $matched->field($biblionumber_tag)->subfield($biblionumber_subfield); |
| 678 |
$matches->{$id}->{score} += $matchpoint->{score}; |
| 679 |
$matches->{$id}->{record} = $matched; |
| 680 |
} |
| 681 |
} |
| 682 |
else { |
| 683 |
foreach my $matched ( @{$searchresults} ) { |
| 684 |
$matches->{$matched}->{score} += $matchpoint->{'score'}; |
| 685 |
$matches->{$matched}->{record} = $matched; |
| 686 |
} |
| 687 |
} |
| 688 |
} |
| 689 |
|
| 668 |
} |
690 |
} |
| 669 |
elsif ( $self->{'record_type'} eq 'authority' ) { |
691 |
elsif ( $self->{'record_type'} eq 'authority' ) { |
| 670 |
my $authresults; |
692 |
my $authresults; |
|
Lines 687-727
sub get_matches {
Link Here
|
| 687 |
'AuthidAsc', 1 |
709 |
'AuthidAsc', 1 |
| 688 |
); |
710 |
); |
| 689 |
foreach my $result (@$authresults) { |
711 |
foreach my $result (@$authresults) { |
| 690 |
push @$searchresults, $result->{'authid'}; |
712 |
my $id = $result->{authid}; |
| 691 |
} |
713 |
$matches->{$id}->{score} += $matchpoint->{'score'}; |
| 692 |
} |
714 |
$matches->{$id}->{record} = $id; |
| 693 |
|
|
|
| 694 |
if ( defined $error ) { |
| 695 |
warn "search failed ($query) $error"; |
| 696 |
} |
| 697 |
else { |
| 698 |
foreach my $matched ( @{$searchresults} ) { |
| 699 |
$matches{$matched} += $matchpoint->{'score'}; |
| 700 |
} |
715 |
} |
| 701 |
} |
716 |
} |
| 702 |
} |
717 |
} |
| 703 |
|
718 |
|
| 704 |
# get rid of any that don't meet the threshold |
719 |
# get rid of any that don't meet the threshold |
| 705 |
%matches = map { ($matches{$_} >= $self->{'threshold'}) ? ($_ => $matches{$_}) : () } keys %matches; |
720 |
$matches = { map { ($matches->{$_}->{score} >= $self->{'threshold'}) ? ($_ => $matches->{$_}) : () } keys %$matches }; |
| 706 |
|
|
|
| 707 |
# get rid of any that don't meet the required checks |
| 708 |
%matches = map { _passes_required_checks($source_record, $_, $self->{'required_checks'}) ? ($_ => $matches{$_}) : () } |
| 709 |
keys %matches unless ($self->{'record_type'} eq 'auth'); |
| 710 |
|
721 |
|
| 711 |
my @results = (); |
722 |
my @results = (); |
| 712 |
if ($self->{'record_type'} eq 'biblio') { |
723 |
if ($self->{'record_type'} eq 'biblio') { |
| 713 |
require C4::Biblio; |
724 |
require C4::Biblio; |
| 714 |
foreach my $marcblob (keys %matches) { |
725 |
# get rid of any that don't meet the required checks |
| 715 |
my $target_record = C4::Search::new_record_from_zebra('biblioserver',$marcblob); |
726 |
$matches = { |
| 716 |
my $record_number; |
727 |
map { |
| 717 |
my $result = C4::Biblio::TransformMarcToKoha($target_record, ''); |
728 |
_passes_required_checks( $source_record, $_, $self->{'required_checks'} ) |
| 718 |
$record_number = $result->{'biblionumber'}; |
729 |
? ( $_ => $matches->{$_} ) |
| 719 |
push @results, { 'record_id' => $record_number, 'score' => $matches{$marcblob} }; |
730 |
: () |
|
|
731 |
} keys %$matches |
| 732 |
}; |
| 733 |
|
| 734 |
foreach my $id ( keys %$matches ) { |
| 735 |
my $target_record = C4::Search::new_record_from_zebra( 'biblioserver', $matches->{$id}->{record} ); |
| 736 |
my $result = C4::Biblio::TransformMarcToKoha( $target_record, $marcframework_used ); |
| 737 |
push @results, { |
| 738 |
record_id => $result->{biblionumber}, |
| 739 |
score => $matches->{$id}->{score} |
| 740 |
}; |
| 720 |
} |
741 |
} |
| 721 |
} elsif ($self->{'record_type'} eq 'authority') { |
742 |
} elsif ($self->{'record_type'} eq 'authority') { |
| 722 |
require C4::AuthoritiesMarc; |
743 |
require C4::AuthoritiesMarc; |
| 723 |
foreach my $authid (keys %matches) { |
744 |
foreach my $id (keys %$matches) { |
| 724 |
push @results, { 'record_id' => $authid, 'score' => $matches{$authid} }; |
745 |
push @results, { |
|
|
746 |
record_id => $id, |
| 747 |
score => $matches->{$id}->{score} |
| 748 |
}; |
| 725 |
} |
749 |
} |
| 726 |
} |
750 |
} |
| 727 |
@results = sort { $b->{'score'} cmp $a->{'score'} } @results; |
751 |
@results = sort { $b->{'score'} cmp $a->{'score'} } @results; |
|
Lines 729-735
sub get_matches {
Link Here
|
| 729 |
@results = @results[0..$max_matches-1]; |
753 |
@results = @results[0..$max_matches-1]; |
| 730 |
} |
754 |
} |
| 731 |
return @results; |
755 |
return @results; |
| 732 |
|
|
|
| 733 |
} |
756 |
} |
| 734 |
|
757 |
|
| 735 |
=head2 dump |
758 |
=head2 dump |
| 736 |
- |
|
|