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

(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-10 / +47 lines)
Lines 24-29 use Koha::Database; Link Here
24
use Koha::SearchEngine::Elasticsearch::QueryBuilder
24
use Koha::SearchEngine::Elasticsearch::QueryBuilder
25
25
26
subtest 'build_authorities_query_compat() tests' => sub {
26
subtest 'build_authorities_query_compat() tests' => sub {
27
    plan tests => 37;
27
28
28
    my $qb;
29
    my $qb;
29
30
Lines 34-48 subtest 'build_authorities_query_compat() tests' => sub { Link Here
34
35
35
    my $koha_to_index_name = $Koha::SearchEngine::Elasticsearch::QueryBuilder::koha_to_index_name;
36
    my $koha_to_index_name = $Koha::SearchEngine::Elasticsearch::QueryBuilder::koha_to_index_name;
36
    my $search_term = 'a';
37
    my $search_term = 'a';
38
    foreach my $koha_name ( keys %{ $koha_to_index_name } ) {
39
        my $query = $qb->build_authorities_query_compat( [ $koha_name ],  undef, undef, ['contains'], [$search_term], 'AUTH_TYPE', 'asc' );
40
        if ( $koha_name eq 'all' ) {
41
            is( $query->{query}->{bool}->{must}[0]->{wildcard}->{"_all.phrase"},
42
                "*a*");
43
        } else {
44
            is( $query->{query}->{bool}->{must}[0]->{wildcard}->{$koha_to_index_name->{$koha_name}.".phrase"},
45
                "*a*");
46
        }
47
    }
37
48
49
    $search_term = 'Donald Duck';
38
    foreach my $koha_name ( keys %{ $koha_to_index_name } ) {
50
    foreach my $koha_name ( keys %{ $koha_to_index_name } ) {
39
        my $query = $qb->build_authorities_query_compat( [ $koha_name ],  undef, undef, ['contains'], [$search_term], 'AUTH_TYPE', 'asc' );
51
        my $query = $qb->build_authorities_query_compat( [ $koha_name ],  undef, undef, ['contains'], [$search_term], 'AUTH_TYPE', 'asc' );
40
        if ( $koha_name eq 'all' ) {
52
        if ( $koha_name eq 'all' ) {
41
            is( $query->{query}->{bool}->{should}[0]->{match}->{_all},
53
            is( $query->{query}->{bool}->{must}[0]->{wildcard}->{"_all.phrase"},
42
                $search_term);
54
                "*donald*");
55
            is( $query->{query}->{bool}->{must}[1]->{wildcard}->{"_all.phrase"},
56
                "*duck*");
57
        } else {
58
            is( $query->{query}->{bool}->{must}[0]->{wildcard}->{$koha_to_index_name->{$koha_name}.".phrase"},
59
                "*donald*");
60
            is( $query->{query}->{bool}->{must}[1]->{wildcard}->{$koha_to_index_name->{$koha_name}.".phrase"},
61
                "*duck*");
62
        }
63
    }
64
65
    foreach my $koha_name ( keys %{ $koha_to_index_name } ) {
66
        my $query = $qb->build_authorities_query_compat( [ $koha_name ],  undef, undef, ['is'], [$search_term], 'AUTH_TYPE', 'asc' );
67
        if ( $koha_name eq 'all' ) {
68
            is( $query->{query}->{bool}->{must}[0]->{term}->{"_all.phrase"},
69
                "donald duck");
70
        } else {
71
            is( $query->{query}->{bool}->{must}[0]->{term}->{$koha_to_index_name->{$koha_name}.".phrase"},
72
                "donald duck");
73
        }
74
    }
75
76
    foreach my $koha_name ( keys %{ $koha_to_index_name } ) {
77
        my $query = $qb->build_authorities_query_compat( [ $koha_name ],  undef, undef, ['start'], [$search_term], 'AUTH_TYPE', 'asc' );
78
        if ( $koha_name eq 'all' ) {
79
            is( $query->{query}->{bool}->{must}[0]->{prefix}->{"_all.lc_raw"},
80
                "donald duck");
43
        } else {
81
        } else {
44
            is( $query->{query}->{bool}->{should}[0]->{match}->{$koha_to_index_name->{$koha_name}},
82
            is( $query->{query}->{bool}->{must}[0]->{prefix}->{$koha_to_index_name->{$koha_name}.".lc_raw"},
45
                $search_term);
83
                "donald duck");
46
        }
84
        }
47
    }
85
    }
48
86
Lines 65-79 subtest 'build query from form subtests' => sub { Link Here
65
103
66
    my $query = $builder->build_authorities_query_compat( \@marclist, undef,
104
    my $query = $builder->build_authorities_query_compat( \@marclist, undef,
67
                    undef, \@operator , \@values, 'AUTH_TYPE', 'asc' );
105
                    undef, \@operator , \@values, 'AUTH_TYPE', 'asc' );
68
    is($query->{query}->{bool}->{should}[0]->{match}->{'Heading'}, "Hamilton","Expected search is populated");
106
    is($query->{query}->{bool}->{must}[0]->{wildcard}->{'Heading.phrase'}, "*hamilton*","Expected search is populated");
69
    is( scalar @{ $query->{query}->{bool}->{should} }, 1,"Only defined search is populated");
107
    is( scalar @{ $query->{query}->{bool}->{must} }, 1,"Only defined search is populated");
70
108
71
    @values[2] = 'Jefferson';
109
    @values[2] = 'Jefferson';
72
    $query = $builder->build_authorities_query_compat( \@marclist, undef,
110
    $query = $builder->build_authorities_query_compat( \@marclist, undef,
73
                    undef, \@operator , \@values, 'AUTH_TYPE', 'asc' );
111
                    undef, \@operator , \@values, 'AUTH_TYPE', 'asc' );
74
    is($query->{query}->{bool}->{should}[0]->{match}->{'Heading'}, "Hamilton","First index searched as expected");
112
    is($query->{query}->{bool}->{must}[0]->{wildcard}->{'Heading.phrase'}, "*hamilton*","First index searched as expected");
75
    is($query->{query}->{bool}->{should}[1]->{match}->{'Match'}, "Jefferson","Second index searched when populated");
113
    is($query->{query}->{bool}->{must}[1]->{wildcard}->{'Match.phrase'}, "*jefferson*","Second index searched when populated");
76
    is( scalar @{ $query->{query}->{bool}->{should} }, 2,"Only defined searches are populated");
114
    is( scalar @{ $query->{query}->{bool}->{must} }, 2,"Only defined searches are populated");
77
115
78
116
79
};
117
};
80
- 

Return to bug 19604