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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-3 / +9 lines)
Lines 511-519 sub build_authorities_query { Link Here
511
    # Merge the query parts appropriately
511
    # Merge the query parts appropriately
512
    # 'should' behaves like 'or'
512
    # 'should' behaves like 'or'
513
    # 'must' behaves like 'and'
513
    # 'must' behaves like 'and'
514
    # Zebra behaviour seem to match must so using that here
514
    # We will obey the first and_or passed in here:
515
    # authfinder.pl is hardcoded to 'AND'
516
    # authorities-home.pl only allows searching a single index
517
    # for matching we 'OR' together multiple fields
518
    my $search_type   = defined $search->{and_or} && uc( $search->{and_or}->[0] ) eq 'OR' ? 'should' : 'must';
515
    my $elastic_query = {};
519
    my $elastic_query = {};
516
    $elastic_query->{bool}->{must} = \@query_parts;
520
    $elastic_query->{bool}->{$search_type} = \@query_parts;
517
521
518
    # Filter by authtypecode if set
522
    # Filter by authtypecode if set
519
    if ( $search->{authtypecode} ) {
523
    if ( $search->{authtypecode} ) {
Lines 549-555 thesaurus. If left blank, any field is used. Link Here
549
553
550
=item and_or
554
=item and_or
551
555
552
Totally ignored. It is never used in L<C4::AuthoritiesMarc::SearchAuthorities>.
556
This takes an array to match Zebra, however, we only care about the first value.
557
This will determine whether searches are combined as 'must' (AND) or 'should' (OR).
553
558
554
=item excluding
559
=item excluding
555
560
Lines 663-668 sub build_authorities_query_compat { Link Here
663
    my %search = (
668
    my %search = (
664
        searches     => \@searches,
669
        searches     => \@searches,
665
        authtypecode => $authtypecode,
670
        authtypecode => $authtypecode,
671
        and_or       => $and_or,
666
    );
672
    );
667
    $search{sort} = \%sort if %sort;
673
    $search{sort} = \%sort if %sort;
668
    my $query = $self->build_authorities_query( \%search );
674
    my $query = $self->build_authorities_query( \%search );
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-4 / +27 lines)
Lines 85-91 $se->mock( Link Here
85
85
86
subtest 'build_authorities_query_compat() tests' => sub {
86
subtest 'build_authorities_query_compat() tests' => sub {
87
87
88
    plan tests => 72;
88
    plan tests => 81;
89
89
90
    my $qb;
90
    my $qb;
91
91
Lines 94-101 subtest 'build_authorities_query_compat() tests' => sub { Link Here
94
        'Creating new query builder object for authorities'
94
        'Creating new query builder object for authorities'
95
    );
95
    );
96
96
97
    my $koha_name   = 'any';
98
    my $search_term = 'a';
99
    my $query       = $qb->build_authorities_query_compat(
100
        [$koha_name], undef, undef, ['contains'], [$search_term], 'AUTH_TYPE',
101
        'asc'
102
    );
103
    ok( !defined $query->{query}->{bool}->{should}, "Should query not used if 'and_or' not passed" );
104
    ok( defined $query->{query}->{bool}->{must},    "Must query used if 'and_or' not passed" );
105
    is( $query->{query}->{bool}->{must}[0]->{query_string}->{query}, "a*" );
106
    $query = $qb->build_authorities_query_compat(
107
        [$koha_name], ['and'], undef, ['contains'], [$search_term], 'AUTH_TYPE',
108
        'asc'
109
    );
110
    ok( !defined $query->{query}->{bool}->{should}, "Should query not used when 'and_or' passed 'and'" );
111
    ok( defined $query->{query}->{bool}->{must},    "Must query used when 'and_or' passed 'and'" );
112
    is( $query->{query}->{bool}->{must}[0]->{query_string}->{query}, "a*" );
113
    $query = $qb->build_authorities_query_compat(
114
        [$koha_name], ['or'], undef, ['contains'], [$search_term], 'AUTH_TYPE',
115
        'asc'
116
    );
117
    ok( defined $query->{query}->{bool}->{should}, "Should query used if 'and_or' passed 'or'" );
118
    ok( defined $query->{query}->{bool}->{should}, "Must query not used if 'and_or' passed 'or'" );
119
    is( $query->{query}->{bool}->{should}[0]->{query_string}->{query}, "a*" );
120
97
    my $koha_to_index_name = $Koha::SearchEngine::Elasticsearch::QueryBuilder::koha_to_index_name;
121
    my $koha_to_index_name = $Koha::SearchEngine::Elasticsearch::QueryBuilder::koha_to_index_name;
98
    my $search_term        = 'a';
122
    $search_term = 'a';
99
    foreach my $koha_name ( keys %{$koha_to_index_name} ) {
123
    foreach my $koha_name ( keys %{$koha_to_index_name} ) {
100
        my $query = $qb->build_authorities_query_compat(
124
        my $query = $qb->build_authorities_query_compat(
101
            [$koha_name], undef, undef, ['contains'], [$search_term], 'AUTH_TYPE',
125
            [$koha_name], undef, undef, ['contains'], [$search_term], 'AUTH_TYPE',
Lines 175-181 subtest 'build_authorities_query_compat() tests' => sub { Link Here
175
    }
199
    }
176
200
177
    # Sorting
201
    # Sorting
178
    my $query = $qb->build_authorities_query_compat(
202
    $query = $qb->build_authorities_query_compat(
179
        ['mainentry'], undef, undef, ['start'], [$search_term], 'AUTH_TYPE',
203
        ['mainentry'], undef, undef, ['start'], [$search_term], 'AUTH_TYPE',
180
        'HeadingAsc'
204
        'HeadingAsc'
181
    );
205
    );
182
- 

Return to bug 39079