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

(-)a/Koha/SearchEngine/Zebra/QueryBuilder.pm (-1 / +1 lines)
Lines 44-50 sub build_query_compat { Link Here
44
    #
44
    #
45
    # add OPAC suppression - requires at least one item indexed with Suppress
45
    # add OPAC suppression - requires at least one item indexed with Suppress
46
    if ($params->{suppress}) {
46
    if ($params->{suppress}) {
47
        if ( $query_type eq 'pqf' ) {
47
        if ( defined $query_type and $query_type eq 'pqf' ) {
48
            #$query = "($query) && -(suppress:1)"; #QP syntax
48
            #$query = "($query) && -(suppress:1)"; #QP syntax
49
            $query = '@not '.$query.' @attr 14=1 @attr 1=9011 1'; #PQF syntax
49
            $query = '@not '.$query.' @attr 14=1 @attr 1=9011 1'; #PQF syntax
50
        } else {
50
        } else {
(-)a/t/Koha/SearchEngine/Zebra/QueryBuilder.t (+78 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
#
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 3 of the License, or
8
# (at your option) any later version.
9
#
10
# Koha is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
use Modern::Perl;
19
20
use Test::More tests => 3;
21
use Test::MockModule;
22
23
use_ok('Koha::SearchEngine::Zebra::QueryBuilder');
24
25
subtest 'build_authorities_query' => sub {
26
    plan tests => 2;
27
28
    my @test_search = (
29
        ['mainmainentry'], ['and'], [''], ['contains'], ['any'], '',
30
        'HeadingAsc'
31
    );
32
    my $expected_result = {
33
        marclist     => ['mainmainentry'],
34
        and_or       => ['and'],
35
        excluding    => [''],
36
        operator     => ['contains'],
37
        value        => ['any'],
38
        authtypecode => '',
39
        orderby      => 'HeadingAsc',
40
    };
41
    my $built_search =
42
      Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search );
43
    is_deeply(
44
        $built_search, $expected_result,
45
        "We are simply hashifying our array of refs/values, should otherwise not be altered"
46
    );
47
    $expected_result->{value} = ['"any"'];
48
    $test_search[4] = ['"any"'];
49
    $built_search =
50
      Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search );
51
    is_deeply(
52
        $built_search, $expected_result,
53
        "The same should hold true if the search contains double quotes which will be escaped during searching by search_auth_compat subroutine"
54
    );
55
};
56
57
subtest 'build_query_compat() tests' => sub {
58
59
    plan tests => 4;
60
61
    my $search = Test::MockModule->new('C4::Search');
62
    $search->mock( 'buildQuery', sub { return ( 'error', 'query', 'simple_query', 'query_cgi', 'query_desc', 'limit', 'limit_cgi', 'limit_desc', 'query_type' ) } );
63
    my $qb = Koha::SearchEngine::Zebra::QueryBuilder->new();
64
    my $query;
65
66
    ( undef, $query ) = $qb->build_query_compat( undef, undef, undef, undef, undef, undef, undef, { suppress => 1 } );
67
    is( $query, '(query) not Suppress=1', 'Suppress part of the query added correctly');
68
69
    ( undef, $query ) = $qb->build_query_compat( undef, undef, undef, undef, undef, undef, undef, { suppress => 0 } );
70
    is( $query, 'query', 'Suppress part of the query not added');
71
72
    $search->mock( 'buildQuery', sub { return ( 'error', 'query', 'simple_query', 'query_cgi', 'query_desc', 'limit', 'limit_cgi', 'limit_desc', 'pqf' ) } );
73
    ( undef, $query ) = $qb->build_query_compat( undef, undef, undef, undef, undef, undef, undef, { suppress => 1 } );
74
    is( $query, '@not query @attr 14=1 @attr 1=9011 1', 'Suppress part of the query added correctly (PQF)');
75
76
    ( undef, $query ) = $qb->build_query_compat( undef, undef, undef, undef, undef, undef, undef, { suppress => 0 } );
77
    is( $query, 'query', 'Suppress part of the query not added (PQF)');
78
};
(-)a/t/Search/Zebra/QueryBuilder.t (-38 lines)
Lines 1-38 Link Here
1
#!/usr/bin/env perl
2
3
use Modern::Perl;
4
5
use Test::More tests => 2;
6
use_ok('Koha::SearchEngine::Zebra::QueryBuilder');
7
8
subtest 'build_authorities_query' => sub {
9
    plan tests => 2;
10
11
    my @test_search = (
12
        ['mainmainentry'], ['and'], [''], ['contains'], ['any'], '',
13
        'HeadingAsc'
14
    );
15
    my $expected_result = {
16
        marclist     => ['mainmainentry'],
17
        and_or       => ['and'],
18
        excluding    => [''],
19
        operator     => ['contains'],
20
        value        => ['any'],
21
        authtypecode => '',
22
        orderby      => 'HeadingAsc',
23
    };
24
    my $built_search =
25
      Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search );
26
    is_deeply(
27
        $built_search, $expected_result,
28
        "We are simply hashifying our array of refs/values, should otherwise not be altered"
29
    );
30
    $expected_result->{value} = ['"any"'];
31
    $test_search[4] = ['"any"'];
32
    $built_search =
33
      Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search );
34
    is_deeply(
35
        $built_search, $expected_result,
36
        "The same should hold true if the search contains double quotes which will be escaped during searching by search_auth_compat subroutine"
37
    );
38
};
(-)a/t/db_dependent/Koha_SearchEngine_Elasticsearch_Search.t (-2 / +15 lines)
Lines 81-87 subtest 'json2marc' => sub { Link Here
81
};
81
};
82
82
83
subtest 'build_query tests' => sub {
83
subtest 'build_query tests' => sub {
84
    plan tests => 16;
84
    plan tests => 18;
85
85
86
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
86
    t::lib::Mocks::mock_preference('DisplayLibraryFacets','both');
87
    my $query = $builder->build_query();
87
    my $query = $builder->build_query();
Lines 178-182 subtest 'build_query tests' => sub { Link Here
178
        '(title:"donald duck")',
178
        '(title:"donald duck")',
179
        "query of specific field is not truncated when surrouned by quotes"
179
        "query of specific field is not truncated when surrouned by quotes"
180
    );
180
    );
181
182
    ( undef, $query ) = $builder->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 1 } );
183
    is(
184
        $query->{query}{query_string}{query},
185
        '(title:"donald duck") AND suppress:0',
186
        "query of specific field is added AND suppress:0"
187
    );
188
189
    ( undef, $query ) = $builder->build_query_compat( undef, ['title:"donald duck"'], undef, undef, undef, undef, undef, { suppress => 0 } );
190
    is(
191
        $query->{query}{query_string}{query},
192
        '(title:"donald duck")',
193
        "query of specific field is not added AND suppress:0"
194
    );
181
};
195
};
182
196
183
- 

Return to bug 16660