|
Lines 675-711
sub get_matches {
Link Here
|
| 675 |
} |
675 |
} |
| 676 |
} |
676 |
} |
| 677 |
|
677 |
|
|
|
678 |
#Collect the results |
| 678 |
if ( defined $error ) { |
679 |
if ( defined $error ) { |
| 679 |
warn "search failed ($query) $error"; |
680 |
warn "search failed ($query) $error"; |
| 680 |
} |
681 |
} |
| 681 |
else { |
682 |
else { |
| 682 |
foreach my $matched ( @{$searchresults} ) { |
683 |
if ($self->{'record_type'} eq 'authority') { |
| 683 |
$matches{$matched} += $matchpoint->{'score'}; |
684 |
foreach my $matched ( @{$searchresults} ) { |
|
|
685 |
$matches{$matched}->{score} += $matchpoint->{'score'}; |
| 686 |
} |
| 687 |
} |
| 688 |
elsif ($self->{'record_type'} eq 'biblio') { |
| 689 |
foreach my $matched ( @{$searchresults} ) { |
| 690 |
my $record = C4::Search::new_record_from_zebra( 'biblioserver', $matched ); |
| 691 |
$matches{$record}->{score} += $matchpoint->{'score'}; #Using $record HASH string representation as the key :) |
| 692 |
$matches{$record}->{record} = $record; |
| 693 |
} |
| 684 |
} |
694 |
} |
|
|
695 |
|
| 685 |
} |
696 |
} |
| 686 |
} |
697 |
} |
| 687 |
|
698 |
|
| 688 |
# get rid of any that don't meet the threshold |
699 |
# get rid of any that don't meet the threshold |
| 689 |
%matches = map { ($matches{$_} >= $self->{'threshold'}) ? ($_ => $matches{$_}) : () } keys %matches; |
700 |
%matches = map { ($matches{$_}->{score} >= $self->{'threshold'}) ? ($_ => $matches{$_}) : () } keys %matches; |
| 690 |
|
701 |
|
| 691 |
# get rid of any that don't meet the required checks |
702 |
# get rid of any that don't meet the required checks |
| 692 |
%matches = map { _passes_required_checks($source_record, $_, $self->{'required_checks'}) ? ($_ => $matches{$_}) : () } |
703 |
%matches = map { _passes_required_checks($source_record, $matches{$_}->{record}, $self->{'required_checks'}) ? ($_ => $matches{$_}) : () } |
| 693 |
keys %matches unless ($self->{'record_type'} eq 'auth'); |
704 |
keys %matches unless ($self->{'record_type'} eq 'auth'); |
| 694 |
|
705 |
|
| 695 |
my @results = (); |
706 |
my @results = (); |
| 696 |
if ($self->{'record_type'} eq 'biblio') { |
707 |
if ($self->{'record_type'} eq 'biblio') { |
| 697 |
require C4::Biblio; |
708 |
require C4::Biblio; |
| 698 |
foreach my $marcblob (keys %matches) { |
709 |
foreach my $hashkey (keys %matches) { |
| 699 |
my $target_record = C4::Search::new_record_from_zebra('biblioserver',$marcblob); |
710 |
my $target_record = $matches{$hashkey}->{record}; |
| 700 |
my $record_number; |
711 |
my $record_number; |
| 701 |
my $result = C4::Biblio::TransformMarcToKoha(C4::Context->dbh, $target_record, ''); |
712 |
my $result = C4::Biblio::TransformMarcToKoha(C4::Context->dbh, $target_record, ''); |
| 702 |
$record_number = $result->{'biblionumber'}; |
713 |
$record_number = $result->{'biblionumber'}; |
| 703 |
push @results, { 'record_id' => $record_number, 'score' => $matches{$marcblob} }; |
714 |
push @results, { 'record_id' => $record_number, 'score' => $matches{$hashkey}->{score}, 'target_record' => $target_record, 'target_biblio' => $result }; |
| 704 |
} |
715 |
} |
| 705 |
} elsif ($self->{'record_type'} eq 'authority') { |
716 |
} elsif ($self->{'record_type'} eq 'authority') { |
| 706 |
require C4::AuthoritiesMarc; |
717 |
require C4::AuthoritiesMarc; |
| 707 |
foreach my $authid (keys %matches) { |
718 |
foreach my $authid (keys %matches) { |
| 708 |
push @results, { 'record_id' => $authid, 'score' => $matches{$authid} }; |
719 |
push @results, { 'record_id' => $authid, 'score' => $matches{$authid}->{score} }; |
| 709 |
} |
720 |
} |
| 710 |
} |
721 |
} |
| 711 |
@results = sort { $b->{'score'} cmp $a->{'score'} } @results; |
722 |
@results = sort { $b->{'score'} cmp $a->{'score'} } @results; |
|
Lines 749-756
sub dump {
Link Here
|
| 749 |
} |
760 |
} |
| 750 |
|
761 |
|
| 751 |
sub _passes_required_checks { |
762 |
sub _passes_required_checks { |
| 752 |
my ($source_record, $target_blob, $matchchecks) = @_; |
763 |
my ($source_record, $target_record, $matchchecks) = @_; |
| 753 |
my $target_record = MARC::Record->new_from_usmarc($target_blob); # FIXME -- need to avoid parsing record twice |
|
|
| 754 |
|
764 |
|
| 755 |
# no checks supplied == automatic pass |
765 |
# no checks supplied == automatic pass |
| 756 |
return 1 if $#{ $matchchecks } == -1; |
766 |
return 1 if $#{ $matchchecks } == -1; |
| 757 |
- |
|
|