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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (+1 lines)
Lines 787-792 sub _create_query_string { Link Here
787
        my $field = $_->{field}    ? $_->{field} . ':'    : '';
787
        my $field = $_->{field}    ? $_->{field} . ':'    : '';
788
788
789
        my $oand = $self->_modify_string_by_type(%$_);
789
        my $oand = $self->_modify_string_by_type(%$_);
790
        $oand = "($oand)" if $field && scalar(split(/\s+/, $oand)) > 1;
790
        "$otor($field$oand)";
791
        "$otor($field$oand)";
791
    } @queries;
792
    } @queries;
792
}
793
}
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-3 / +30 lines)
Lines 169-175 subtest 'build_authorities_query_compat() tests' => sub { Link Here
169
};
169
};
170
170
171
subtest 'build_query tests' => sub {
171
subtest 'build_query tests' => sub {
172
    plan tests => 26;
172
    plan tests => 30;
173
173
174
    my $qb;
174
    my $qb;
175
175
Lines 224-229 subtest 'build_query tests' => sub { Link Here
224
        "query not altered if QueryAutoTruncate disabled"
224
        "query not altered if QueryAutoTruncate disabled"
225
    );
225
    );
226
226
227
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'], ['title'] );
228
    is(
229
        $query->{query}{query_string}{query},
230
        '(title:(donald duck))',
231
        'multiple words in a query term are enclosed in parenthesis'
232
    );
233
234
    ( undef, $query ) = $qb->build_query_compat( ['AND'], ['donald duck', 'disney'], ['title', 'author'] );
235
    is(
236
        $query->{query}{query_string}{query},
237
        '(title:(donald duck)) AND (author:disney)',
238
        'multiple query terms are enclosed in parenthesis while a single one is not'
239
    );
240
227
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
241
    t::lib::Mocks::mock_preference( 'QueryAutoTruncate', '1' );
228
242
229
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
243
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'] );
Lines 324-330 subtest 'build_query tests' => sub { Link Here
324
    is(
338
    is(
325
        $query->{query}{query_string}{query},
339
        $query->{query}{query_string}{query},
326
        '(title:"donald duck")',
340
        '(title:"donald duck")',
327
        "query of specific field is not truncated when surrouned by quotes"
341
        "query of specific field is not truncated when surrounded by quotes"
342
    );
343
344
    ( undef, $query ) = $qb->build_query_compat( undef, ['donald duck'], ['title'] );
345
    is(
346
        $query->{query}{query_string}{query},
347
        '(title:(donald* duck*))',
348
        'words of a multi-word term are properly truncated'
349
    );
350
351
    ( undef, $query ) = $qb->build_query_compat( ['AND'], ['donald duck', 'disney'], ['title', 'author'] );
352
    is(
353
        $query->{query}{query_string}{query},
354
        '(title:(donald* duck*)) AND (author:disney*)',
355
        'words of a multi-word term and single-word term are properly truncated'
328
    );
356
    );
329
357
330
    ( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 1 } );
358
    ( undef, $query ) = $qb->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 1 } );
331
- 

Return to bug 22295