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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-3 / +9 lines)
Lines 472-480 sub build_authorities_query { Link Here
472
    # Merge the query parts appropriately
472
    # Merge the query parts appropriately
473
    # 'should' behaves like 'or'
473
    # 'should' behaves like 'or'
474
    # 'must' behaves like 'and'
474
    # 'must' behaves like 'and'
475
    # Zebra behaviour seem to match must so using that here
475
    # We will obey the first and_or passed in here:
476
    # authfinder.pl is hardcoded to 'AND'
477
    # authorities-home.pl only allows searching a single index
478
    # for matching we 'OR' together multiple fields
479
    my $search_type   = defined $search->{and_or} && uc( $search->{and_or}->[0] ) eq 'OR' ? 'should' : 'must';
476
    my $elastic_query = {};
480
    my $elastic_query = {};
477
    $elastic_query->{bool}->{must} = \@query_parts;
481
    $elastic_query->{bool}->{$search_type} = \@query_parts;
478
482
479
    # Filter by authtypecode if set
483
    # Filter by authtypecode if set
480
    if ( $search->{authtypecode} ) {
484
    if ( $search->{authtypecode} ) {
Lines 510-516 thesaurus. If left blank, any field is used. Link Here
510
514
511
=item and_or
515
=item and_or
512
516
513
Totally ignored. It is never used in L<C4::AuthoritiesMarc::SearchAuthorities>.
517
This takes an array to match Zebra, however, we only care about the first value.
518
This will determine whether searches are combined as 'must' (AND) or 'should' (OR).
514
519
515
=item excluding
520
=item excluding
516
521
Lines 624-629 sub build_authorities_query_compat { Link Here
624
    my %search = (
629
    my %search = (
625
        searches     => \@searches,
630
        searches     => \@searches,
626
        authtypecode => $authtypecode,
631
        authtypecode => $authtypecode,
632
        and_or       => $and_or,
627
    );
633
    );
628
    $search{sort} = \%sort if %sort;
634
    $search{sort} = \%sort if %sort;
629
    my $query = $self->build_authorities_query( \%search );
635
    my $query = $self->build_authorities_query( \%search );
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-3 / +26 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',
102
- 

Return to bug 39079