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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-3 / +7 lines)
Lines 285-291 sub build_authorities_query { Link Here
285
285
286
    foreach my $s ( @{ $search->{searches} } ) {
286
    foreach my $s ( @{ $search->{searches} } ) {
287
        my ( $wh, $op, $val ) = @{$s}{qw(where operator value)};
287
        my ( $wh, $op, $val ) = @{$s}{qw(where operator value)};
288
        if ( $op eq 'is' || $op eq '=' || $op eq 'exact') {
288
        if ( defined $op && ($op eq 'is' || $op eq '=' || $op eq 'exact') ) {
289
            if ($wh) {
289
            if ($wh) {
290
                # Match the whole field, case insensitive, UTF normalized.
290
                # Match the whole field, case insensitive, UTF normalized.
291
                push @query_parts, { term => { "$wh.ci_raw" => $val } };
291
                push @query_parts, { term => { "$wh.ci_raw" => $val } };
Lines 304-310 sub build_authorities_query { Link Here
304
                };
304
                };
305
            }
305
            }
306
        }
306
        }
307
        elsif ( $op eq 'start') {
307
        elsif ( defined $op && $op eq 'start') {
308
            # Match the prefix within a field for all searchable fields.
308
            # Match the prefix within a field for all searchable fields.
309
            # Given that field data is "The quick brown fox"
309
            # Given that field data is "The quick brown fox"
310
            # "The quick bro" will match, but not "quick bro"
310
            # "The quick bro" will match, but not "quick bro"
Lines 464-469 sub build_authorities_query_compat { Link Here
464
    # This turns the old-style many-options argument form into a more
464
    # This turns the old-style many-options argument form into a more
465
    # extensible hash form that is understood by L<build_authorities_query>.
465
    # extensible hash form that is understood by L<build_authorities_query>.
466
    my @searches;
466
    my @searches;
467
    my $mappings = $self->get_elasticsearch_mappings();
467
468
468
    # Convert to lower case
469
    # Convert to lower case
469
    $marclist = [map(lc, @{$marclist})];
470
    $marclist = [map(lc, @{$marclist})];
Lines 472-478 sub build_authorities_query_compat { Link Here
472
    my @indexes;
473
    my @indexes;
473
    # Make sure everything exists
474
    # Make sure everything exists
474
    foreach my $m (@$marclist) {
475
    foreach my $m (@$marclist) {
475
        push @indexes, exists $koha_to_index_name->{$m} ? $koha_to_index_name->{$m} : $m;
476
477
        $m = exists $koha_to_index_name->{$m} ? $koha_to_index_name->{$m} : $m;
478
        push @indexes, $m;
479
        warn "Unknown search field $m in marclist" unless (defined $mappings->{data}->{properties}->{$m} || $m eq '');
476
    }
480
    }
477
    for ( my $i = 0 ; $i < @$value ; $i++ ) {
481
    for ( my $i = 0 ; $i < @$value ; $i++ ) {
478
        next unless $value->[$i]; #clean empty form values, ES doesn't like undefined searches
482
        next unless $value->[$i]; #clean empty form values, ES doesn't like undefined searches
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-6 / +26 lines)
Lines 19-24 use Modern::Perl; Link Here
19
19
20
use C4::Context;
20
use C4::Context;
21
use Test::Exception;
21
use Test::Exception;
22
use Test::Warn;
22
use t::lib::Mocks;
23
use t::lib::Mocks;
23
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
24
use Test::More tests => 6;
25
use Test::More tests => 6;
Lines 50-55 $se->mock( 'get_elasticsearch_mappings', sub { Link Here
50
                    type => 'text',
51
                    type => 'text',
51
                    facet => 1
52
                    facet => 1
52
                },
53
                },
54
                'subject-heading-thesaurus' => {
55
                    type => 'text',
56
                    facet => 1
57
                },
53
                itemnumber => {
58
                itemnumber => {
54
                    type => 'integer'
59
                    type => 'integer'
55
                },
60
                },
Lines 59-70 $se->mock( 'get_elasticsearch_mappings', sub { Link Here
59
                sortablenumber__sort => {
64
                sortablenumber__sort => {
60
                    type => 'integer'
65
                    type => 'integer'
61
                },
66
                },
62
                Heading => {
67
                heading => {
63
                    type => 'text'
68
                    type => 'text'
64
                },
69
                },
65
                Heading__sort => {
70
                'heading-main' => {
66
                    type => 'text'
71
                    type => 'text'
67
                }
72
                },
73
                heading__sort => {
74
                    type => 'text'
75
                },
76
                match => {
77
                    type => 'text'
78
                },
79
                'match-heading' => {
80
                    type => 'text'
81
                },
82
                'match-heading-see-from' => {
83
                    type => 'text'
84
                },
68
            }
85
            }
69
        }
86
        }
70
    };
87
    };
Lines 92-98 my $clear_search_fields_cache = sub { Link Here
92
109
93
subtest 'build_authorities_query_compat() tests' => sub {
110
subtest 'build_authorities_query_compat() tests' => sub {
94
111
95
    plan tests => 56;
112
    plan tests => 57;
96
113
97
    my $qb;
114
    my $qb;
98
115
Lines 186-192 subtest 'build_authorities_query_compat() tests' => sub { Link Here
186
    );
203
    );
187
204
188
    # Authorities marclist check
205
    # Authorities marclist check
189
    $query = $qb->build_authorities_query_compat( [ 'tomas','mainentry' ],  undef, undef, ['contains'], [$search_term,$search_term], 'AUTH_TYPE', 'asc' );
206
    warning_like { 
207
        $query = $qb->build_authorities_query_compat( [ 'tomas','mainentry' ],  undef, undef, ['contains'], [$search_term,$search_term], 'AUTH_TYPE', 'asc' )
208
    }
209
    qr/Unknown search field tomas/, 
210
    "Warning for unknown field in marclist";
190
    is_deeply(
211
    is_deeply(
191
        $query->{query}->{bool}->{must}[0]->{query_string}->{default_field},
212
        $query->{query}->{bool}->{must}[0]->{query_string}->{default_field},
192
        'tomas',
213
        'tomas',
193
- 

Return to bug 23719