Lines 689-725
sub get_matches {
Link Here
|
689 |
} |
689 |
} |
690 |
} |
690 |
} |
691 |
|
691 |
|
|
|
692 |
#Collect the results |
692 |
if ( defined $error ) { |
693 |
if ( defined $error ) { |
693 |
warn "search failed ($query) $error"; |
694 |
warn "search failed ($query) $error"; |
694 |
} |
695 |
} |
695 |
else { |
696 |
else { |
696 |
foreach my $matched ( @{$searchresults} ) { |
697 |
if ($self->{'record_type'} eq 'authority') { |
697 |
$matches{$matched} += $matchpoint->{'score'}; |
698 |
foreach my $matched ( @{$searchresults} ) { |
|
|
699 |
$matches{$matched}->{score} += $matchpoint->{'score'}; |
700 |
} |
701 |
} |
702 |
elsif ($self->{'record_type'} eq 'biblio') { |
703 |
foreach my $matched ( @{$searchresults} ) { |
704 |
my $record = C4::Search::new_record_from_zebra( 'biblioserver', $matched ); |
705 |
$matches{$record}->{score} += $matchpoint->{'score'}; #Using $record HASH string representation as the key :) |
706 |
$matches{$record}->{record} = $record; |
707 |
} |
698 |
} |
708 |
} |
|
|
709 |
|
699 |
} |
710 |
} |
700 |
} |
711 |
} |
701 |
|
712 |
|
702 |
# get rid of any that don't meet the threshold |
713 |
# get rid of any that don't meet the threshold |
703 |
%matches = map { ($matches{$_} >= $self->{'threshold'}) ? ($_ => $matches{$_}) : () } keys %matches; |
714 |
%matches = map { ($matches{$_}->{score} >= $self->{'threshold'}) ? ($_ => $matches{$_}) : () } keys %matches; |
704 |
|
715 |
|
705 |
# get rid of any that don't meet the required checks |
716 |
# get rid of any that don't meet the required checks |
706 |
%matches = map { _passes_required_checks($source_record, $_, $self->{'required_checks'}) ? ($_ => $matches{$_}) : () } |
717 |
%matches = map { _passes_required_checks($source_record, $matches{$_}->{record}, $self->{'required_checks'}) ? ($_ => $matches{$_}) : () } |
707 |
keys %matches unless ($self->{'record_type'} eq 'auth'); |
718 |
keys %matches unless ($self->{'record_type'} eq 'auth'); |
708 |
|
719 |
|
709 |
my @results = (); |
720 |
my @results = (); |
710 |
if ($self->{'record_type'} eq 'biblio') { |
721 |
if ($self->{'record_type'} eq 'biblio') { |
711 |
require C4::Biblio; |
722 |
require C4::Biblio; |
712 |
foreach my $marcblob (keys %matches) { |
723 |
foreach my $hashkey (keys %matches) { |
713 |
my $target_record = C4::Search::new_record_from_zebra('biblioserver',$marcblob); |
724 |
my $target_record = $matches{$hashkey}->{record}; |
714 |
my $record_number; |
725 |
my $record_number; |
715 |
my $result = C4::Biblio::TransformMarcToKoha(C4::Context->dbh, $target_record, ''); |
726 |
my $result = C4::Biblio::TransformMarcToKoha(C4::Context->dbh, $target_record, ''); |
716 |
$record_number = $result->{'biblionumber'}; |
727 |
$record_number = $result->{'biblionumber'}; |
717 |
push @results, { 'record_id' => $record_number, 'score' => $matches{$marcblob} }; |
728 |
push @results, { 'record_id' => $record_number, 'score' => $matches{$hashkey}->{score}, 'target_record' => $target_record, 'target_biblio' => $result }; |
718 |
} |
729 |
} |
719 |
} elsif ($self->{'record_type'} eq 'authority') { |
730 |
} elsif ($self->{'record_type'} eq 'authority') { |
720 |
require C4::AuthoritiesMarc; |
731 |
require C4::AuthoritiesMarc; |
721 |
foreach my $authid (keys %matches) { |
732 |
foreach my $authid (keys %matches) { |
722 |
push @results, { 'record_id' => $authid, 'score' => $matches{$authid} }; |
733 |
push @results, { 'record_id' => $authid, 'score' => $matches{$authid}->{score} }; |
723 |
} |
734 |
} |
724 |
} |
735 |
} |
725 |
@results = sort { $b->{'score'} cmp $a->{'score'} } @results; |
736 |
@results = sort { $b->{'score'} cmp $a->{'score'} } @results; |
Lines 763-770
sub dump {
Link Here
|
763 |
} |
774 |
} |
764 |
|
775 |
|
765 |
sub _passes_required_checks { |
776 |
sub _passes_required_checks { |
766 |
my ($source_record, $target_blob, $matchchecks) = @_; |
777 |
my ($source_record, $target_record, $matchchecks) = @_; |
767 |
my $target_record = MARC::Record->new_from_usmarc($target_blob); # FIXME -- need to avoid parsing record twice |
|
|
768 |
|
778 |
|
769 |
# no checks supplied == automatic pass |
779 |
# no checks supplied == automatic pass |
770 |
return 1 if $#{ $matchchecks } == -1; |
780 |
return 1 if $#{ $matchchecks } == -1; |
771 |
- |
|
|