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

(-)a/t/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-1 / +31 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 6;
20
use Test::More tests => 7;
21
use t::lib::Mocks;
21
use t::lib::Mocks;
22
22
23
use_ok('Koha::SearchEngine::Elasticsearch::QueryBuilder');
23
use_ok('Koha::SearchEngine::Elasticsearch::QueryBuilder');
Lines 152-157 subtest '_truncate_terms() tests' => sub { Link Here
152
    is_deeply($res, '"donald   duck"', 'quoted search terms surrounded by spaces correctly');
152
    is_deeply($res, '"donald   duck"', 'quoted search terms surrounded by spaces correctly');
153
};
153
};
154
154
155
subtest '_is_safe_to_auto_truncate() tests' => sub {
156
    plan tests => 7;
157
158
    my $qb;
159
    ok(
160
        $qb = Koha::SearchEngine::Elasticsearch::QueryBuilder->new(
161
            { 'index' => $Koha::SearchEngine::Elasticsearch::BIBLIOS_INDEX }
162
        ),
163
        'Creating a new QueryBuilder object'
164
    );
165
166
    my $res = $qb->_is_safe_to_auto_truncate( undef, 'local-number:1' );
167
    is( $res, '0', 'no truncation for biblionumber - OK' );
168
169
    $res = $qb->_is_safe_to_auto_truncate( undef, 'koha-auth-number:1' );
170
    is( $res, '0', 'no truncation for authid - OK' );
171
172
    $res = $qb->_is_safe_to_auto_truncate( undef, 'title:some title' );
173
    is( $res, '1', 'do truncate titles - OK' );
174
175
    $res = $qb->_is_safe_to_auto_truncate( 'local-number', undef );
176
    is( $res, '0', 'no truncation for biblionumber - OK' );
177
178
    $res = $qb->_is_safe_to_auto_truncate( 'koha-auth-number', undef );
179
    is( $res, '0', 'no truncation for authid - OK' );
180
181
    $res = $qb->_is_safe_to_auto_truncate( 'title', undef );
182
    is( $res, '1', 'do truncate titles - OK' );
183
};
184
155
subtest '_split_query() tests' => sub {
185
subtest '_split_query() tests' => sub {
156
    plan tests => 7;
186
    plan tests => 7;
157
187
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-10 / +36 lines)
Lines 219-225 subtest 'build_authorities_query_compat() tests' => sub { Link Here
219
};
219
};
220
220
221
subtest 'build_query tests' => sub {
221
subtest 'build_query tests' => sub {
222
    plan tests => 60;
222
    plan tests => 63;
223
223
224
    my $qb;
224
    my $qb;
225
225
Lines 406-411 subtest 'build_query tests' => sub { Link Here
406
        "all quoted strings are unaltered if more than one in query"
406
        "all quoted strings are unaltered if more than one in query"
407
    );
407
    );
408
408
409
    # Reset ESPreventAutoTruncate syspref
410
    t::lib::Mocks::mock_preference( 'ESPreventAutoTruncate', '' );
411
409
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode:123456'] );
412
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode:123456'] );
410
    is(
413
    is(
411
        $query->{query}{query_string}{query},
414
        $query->{query}{query_string}{query},
Lines 413-446 subtest 'build_query tests' => sub { Link Here
413
        "query of specific field is truncated"
416
        "query of specific field is truncated"
414
    );
417
    );
415
418
416
    ( undef, $query ) = $qb->build_query_compat( undef, ['Local-number:"123456"'] );
419
    ( undef, $query ) = $qb->build_query_compat( undef, ['Personal-name:"donald"'] );
417
    is(
420
    is(
418
        $query->{query}{query_string}{query},
421
        $query->{query}{query_string}{query},
419
        '(local-number:"123456")',
422
        '(personal-name:"donald")',
420
        "query of specific field including hyphen and quoted is not truncated, field name is converted to lower case"
423
        "query of specific field including hyphen and quoted is not truncated, field name is converted to lower case"
421
    );
424
    );
422
425
423
    ( undef, $query ) = $qb->build_query_compat( undef, ['Local-number:123456'] );
426
    ( undef, $query ) = $qb->build_query_compat( undef, ['Personal-name:donald'] );
424
    is(
427
    is(
425
        $query->{query}{query_string}{query},
428
        $query->{query}{query_string}{query},
426
        '(local-number:123456*)',
429
        '(personal-name:donald*)',
427
        "query of specific field including hyphen and not quoted is truncated, field name is converted to lower case"
430
        "query of specific field including hyphen and not quoted is truncated, field name is converted to lower case"
428
    );
431
    );
429
432
430
    ( undef, $query ) = $qb->build_query_compat( undef, ['Local-number.raw:123456'] );
433
    ( undef, $query ) = $qb->build_query_compat( undef, ['Personal-name.raw:donald'] );
431
    is(
434
    is(
432
        $query->{query}{query_string}{query},
435
        $query->{query}{query_string}{query},
433
        '(local-number.raw:123456*)',
436
        '(personal-name.raw:donald*)',
434
        "query of specific field including period and not quoted is truncated, field name is converted to lower case"
437
        "query of specific field including period and not quoted is truncated, field name is converted to lower case"
435
    );
438
    );
436
439
437
    ( undef, $query ) = $qb->build_query_compat( undef, ['Local-number.raw:"123456"'] );
440
    ( undef, $query ) = $qb->build_query_compat( undef, ['Personal-name.raw:"donald"'] );
438
    is(
441
    is(
439
        $query->{query}{query_string}{query},
442
        $query->{query}{query_string}{query},
440
        '(local-number.raw:"123456")',
443
        '(personal-name.raw:"donald")',
441
        "query of specific field including period and quoted is not truncated, field name is converted to lower case"
444
        "query of specific field including period and quoted is not truncated, field name is converted to lower case"
442
    );
445
    );
443
446
447
    # Set ESPreventAutoTruncate syspref
448
    t::lib::Mocks::mock_preference( 'ESPreventAutoTruncate', 'barcode' );
449
450
    ( undef, $query ) = $qb->build_query_compat( undef, ['barcode:123456'] );
451
    is(
452
        $query->{query}{query_string}{query},
453
        '(barcode:123456)',
454
        "query of specific field excluded by ESPreventAutoTruncate is not truncated"
455
    );
456
457
    ( undef, $query ) = $qb->build_query_compat( undef, ['Local-number:123456'] );
458
    is(
459
        $query->{query}{query_string}{query},
460
        '(local-number:123456)',
461
        "query of identifier is not truncated even if QueryAutoTruncate is set"
462
    );
463
464
    ( undef, $query ) = $qb->build_query_compat( undef, ['onloan:true'] );
465
    is(
466
        $query->{query}{query_string}{query},
467
        '(onloan:true)',
468
        "query of boolean type field is not truncated even if QueryAutoTruncate is set"
469
    );
470
444
    ( undef, $query ) = $qb->build_query_compat( undef, ['J.R.R'] );
471
    ( undef, $query ) = $qb->build_query_compat( undef, ['J.R.R'] );
445
    is(
472
    is(
446
        $query->{query}{query_string}{query},
473
        $query->{query}{query_string}{query},
447
- 

Return to bug 32707