View | Details | Raw Unified | Return to bug 18131
Collapse All | Expand All

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

Return to bug 18131