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

(-)a/C4/Matcher.pm (-15 / +2 lines)
Lines 686-711 sub get_matches { Link Here
686
        my $total_hits;
686
        my $total_hits;
687
        if ( $self->{'record_type'} eq 'biblio' ) {
687
        if ( $self->{'record_type'} eq 'biblio' ) {
688
688
689
            my $phr =
690
                ( C4::Context->preference('AggressiveMatchOnISBN') || C4::Context->preference('AggressiveMatchOnISSN') )
691
                ? ',phr'
692
                : q{};
693
            $query = join(
694
                " OR ",
695
                map { "$matchpoint->{'index'}$phr=\"$_\"" } @source_keys
696
            );
697
698
            #NOTE: double-quote the values so you don't get a "Embedded truncation not supported" error when a term has a ? in it.
699
700
            # Use state variables to avoid recreating the objects every time.
689
            # Use state variables to avoid recreating the objects every time.
701
            # With Elasticsearch this also avoids creating a massive amount of
690
            # With Elasticsearch this also avoids creating a massive amount of
702
            # ES connectors that would eventually run out of file descriptors.
691
            # ES connectors that would eventually run out of file descriptors.
703
            state $query_builder =
692
            state $query_builder =
704
                Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
693
                Koha::SearchEngine::QueryBuilder->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
705
            ( undef, $query ) = $query_builder->build_query_compat(
694
            $query = $query_builder->build_biblio_match_query_compat(
706
                undef, [$query], undef, undef, undef, undef, undef,
695
                { matchpoint => $matchpoint, source_keys => \@source_keys } );
707
                { skip_facets => 1 }
708
            );
709
            state $searcher = Koha::SearchEngine::Search->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
696
            state $searcher = Koha::SearchEngine::Search->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } );
710
            ( $error, $searchresults, $total_hits ) =
697
            ( $error, $searchresults, $total_hits ) =
711
                $searcher->simple_search_compat( $query, 0, $max_matches, undef, skip_normalize => 1 );
698
                $searcher->simple_search_compat( $query, 0, $max_matches, undef, skip_normalize => 1 );
(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (+32 lines)
Lines 254-259 sub build_query { Link Here
254
    return $res;
254
    return $res;
255
}
255
}
256
256
257
=head2 build_biblio_match_query_compat
258
259
    Used only for record matching.
260
    Skip normal query build and generate a constant score terms query, just returning the simple query
261
    so that Matcher can process.
262
    This should reduce some searchign overhead since relevancy doesn't much matter here.
263
264
265
    my $query =
266
        build_biblio_match_query_compat({ matchpoint => $matchpoint, source_keys => $source_keys})
267
268
=cut
269
270
sub build_biblio_match_query_compat {
271
272
    my $self = shift;
273
    my ($params) = @_;
274
275
    my $query;
276
277
    # The 'terms' query doesn't work well on 'text' fields that are analyzed, and we
278
    # aren't analyzing the fields from incoming records, so we use the 'raw' field
279
    # FIXME: We can probably combine the searches for all matchpoints into a single query
280
    $query->{query}->{constant_score}->{filter}->{terms} = {
281
        $params->{matchpoint}->{index} . '.raw' => $params->{source_keys},
282
        boost                                   => $params->{matchpoint}->{score},
283
    };
284
285
    return $query;
286
287
}
288
257
=head2 build_query_compat
289
=head2 build_query_compat
258
290
259
    my (
291
    my (
(-)a/Koha/SearchEngine/Zebra/QueryBuilder.pm (-1 / +33 lines)
Lines 55-60 sub build_query { Link Here
55
    C4::Search::buildQuery @_;
55
    C4::Search::buildQuery @_;
56
}
56
}
57
57
58
=head2 build_biblio_match_query_compat
59
60
    Used only for record matching.
61
    Handle some isbn processing and pass through build_query_compat, just returning the simple query
62
    so that Matcher can process.
63
64
    my $query =
65
        build_biblio_match_query_compat({ matchpoint => $matchpoint, source_keys => $source_keys})
66
67
=cut
68
69
sub build_biblio_match_query_compat {
70
    my $self = shift;
71
    my ($params) = @_;
72
73
    my $phr =
74
        ( C4::Context->preference('AggressiveMatchOnISBN') || C4::Context->preference('AggressiveMatchOnISSN') )
75
        ? ',phr'
76
        : q{};
77
    my $joined_query = join(
78
        " OR ",
79
        map { "$params->{matchpoint}->{'index'}$phr=\"$_\"" } @{ $params->{source_keys} }
80
    );
81
82
    my ( undef, $query ) = $self->build_query_compat(
83
        undef, [$joined_query], undef, undef, undef, undef, undef,
84
        { skip_facets => 1 }
85
    );
86
87
    return $query;
88
89
}
90
58
=head2 build_query_compat
91
=head2 build_query_compat
59
92
60
    my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) =
93
    my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type) =
61
- 

Return to bug 39790