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

(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-3 / +9 lines)
Lines 469-477 sub build_authorities_query { Link Here
469
    # Merge the query parts appropriately
469
    # Merge the query parts appropriately
470
    # 'should' behaves like 'or'
470
    # 'should' behaves like 'or'
471
    # 'must' behaves like 'and'
471
    # 'must' behaves like 'and'
472
    # Zebra behaviour seem to match must so using that here
472
    # We will obey the first and_or passed in here:
473
    # authfinder.pl is hardcoded to 'AND'
474
    # authorities-home.pl only allows searching a single index
475
    # for matching we 'OR' together multiple fields
476
    my $search_type = defined $search->{and_or} && uc($search->{and_or}->[0]) eq 'OR' ? 'should' : 'must';
473
    my $elastic_query = {};
477
    my $elastic_query = {};
474
    $elastic_query->{bool}->{must} = \@query_parts;
478
    $elastic_query->{bool}->{$search_type} = \@query_parts;
475
479
476
    # Filter by authtypecode if set
480
    # Filter by authtypecode if set
477
    if ($search->{authtypecode}) {
481
    if ($search->{authtypecode}) {
Lines 513-519 thesaurus. If left blank, any field is used. Link Here
513
517
514
=item and_or
518
=item and_or
515
519
516
Totally ignored. It is never used in L<C4::AuthoritiesMarc::SearchAuthorities>.
520
This takes an array to match Zebra, however, we only care about the first value.
521
This will determine whether searches are combined as 'must' (AND) or 'should' (OR).
517
522
518
=item excluding
523
=item excluding
519
524
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 105-111 $se->mock( 'get_elasticsearch_mappings', sub { Link Here
105
105
106
subtest 'build_authorities_query_compat() tests' => sub {
106
subtest 'build_authorities_query_compat() tests' => sub {
107
107
108
    plan tests => 72;
108
    plan tests => 81;
109
109
110
    my $qb;
110
    my $qb;
111
111
Lines 114-121 subtest 'build_authorities_query_compat() tests' => sub { Link Here
114
        'Creating new query builder object for authorities'
114
        'Creating new query builder object for authorities'
115
    );
115
    );
116
116
117
    my $koha_to_index_name = $Koha::SearchEngine::Elasticsearch::QueryBuilder::koha_to_index_name;
117
    my $koha_name = 'any';
118
    my $search_term = 'a';
118
    my $search_term = 'a';
119
    my $query = $qb->build_authorities_query_compat(
120
        [$koha_name], undef, undef, ['contains'], [$search_term], 'AUTH_TYPE',
121
        'asc'
122
    );
123
    ok( !defined $query->{query}->{bool}->{should}, "Should query not used if 'and_or' not passed" );
124
    ok( defined $query->{query}->{bool}->{must},    "Must query used if 'and_or' not passed" );
125
    is( $query->{query}->{bool}->{must}[0]->{query_string}->{query}, "a*" );
126
    $query = $qb->build_authorities_query_compat(
127
        [$koha_name], ['and'], undef, ['contains'], [$search_term], 'AUTH_TYPE',
128
        'asc'
129
    );
130
    ok( !defined $query->{query}->{bool}->{should}, "Should query not used when 'and_or' passed 'and'" );
131
    ok( defined $query->{query}->{bool}->{must},    "Must query used when 'and_or' passed 'and'" );
132
    is( $query->{query}->{bool}->{must}[0]->{query_string}->{query}, "a*" );
133
    $query = $qb->build_authorities_query_compat(
134
        [$koha_name], ['or'], undef, ['contains'], [$search_term], 'AUTH_TYPE',
135
        'asc'
136
    );
137
    ok( defined $query->{query}->{bool}->{should}, "Should query used if 'and_or' passed 'or'" );
138
    ok( defined $query->{query}->{bool}->{should}, "Must query not used if 'and_or' passed 'or'" );
139
    is( $query->{query}->{bool}->{should}[0]->{query_string}->{query}, "a*" );
140
141
    my $koha_to_index_name = $Koha::SearchEngine::Elasticsearch::QueryBuilder::koha_to_index_name;
142
    $search_term = 'a';
119
    foreach my $koha_name ( keys %{ $koha_to_index_name } ) {
143
    foreach my $koha_name ( keys %{ $koha_to_index_name } ) {
120
        my $query = $qb->build_authorities_query_compat( [ $koha_name ],  undef, undef, ['contains'], [$search_term], 'AUTH_TYPE', 'asc' );
144
        my $query = $qb->build_authorities_query_compat( [ $koha_name ],  undef, undef, ['contains'], [$search_term], 'AUTH_TYPE', 'asc' );
121
        if ( $koha_name eq 'all' || $koha_name eq 'any' ) {
145
        if ( $koha_name eq 'all' || $koha_name eq 'any' ) {
122
- 

Return to bug 39079