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

(-)a/C4/AuthoritiesMarc.pm (-2 / +15 lines)
Lines 108-121 sub GetAuthMARCFromKohaField { Link Here
108
108
109
  (\@finalresult, $nbresults)= &SearchAuthorities($tags, $and_or, 
109
  (\@finalresult, $nbresults)= &SearchAuthorities($tags, $and_or, 
110
     $excluding, $operator, $value, $offset,$length,$authtypecode,
110
     $excluding, $operator, $value, $offset,$length,$authtypecode,
111
     $sortby[, $skipmetadata])
111
     $sortby[, $skipmetadata, $est_headings])
112
112
113
returns ref to array result and count of results returned
113
returns ref to array result and count of results returned
114
114
115
=cut
115
=cut
116
116
117
sub SearchAuthorities {
117
sub SearchAuthorities {
118
    my ($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby,$skipmetadata) = @_;
118
    my ($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby,$skipmetadata,$est_headings) = @_;
119
    # warn Dumper($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby);
119
    # warn Dumper($tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode,$sortby);
120
    my $dbh=C4::Context->dbh;
120
    my $dbh=C4::Context->dbh;
121
    $sortby="" unless $sortby;
121
    $sortby="" unless $sortby;
Lines 139-144 sub SearchAuthorities { Link Here
139
            while ($n>1){$query= "\@or ".$query;$n--;}
139
            while ($n>1){$query= "\@or ".$query;$n--;}
140
        }
140
        }
141
    }
141
    }
142
    ## optionally search for established headings
143
    if ($est_headings) {
144
        $query = "\@and " . $query;
145
        my $n          = 0;
146
        my @est_values = ( 'a', 'f', '|' );
147
        foreach my $v (@est_values) {
148
            $query .= " \@attr 1=Kind-of-record \@attr 5=100 " . $v;
149
            $n++;
150
        }
151
        if ( $n > 1 ) {
152
            while ( $n > 1 ) { $query = "\@or " . $query; $n--; }
153
        }
154
    }
142
155
143
    my $dosearch;
156
    my $dosearch;
144
    my $and=" \@and " ;
157
    my $and=" \@and " ;
(-)a/Koha/SearchEngine/Elasticsearch/QueryBuilder.pm (-5 / +17 lines)
Lines 468-482 sub build_authorities_query { Link Here
468
    my $elastic_query = {};
468
    my $elastic_query = {};
469
    $elastic_query->{bool}->{must} = \@query_parts;
469
    $elastic_query->{bool}->{must} = \@query_parts;
470
470
471
    # further filter the results
472
    my @filters;
473
471
    # Filter by authtypecode if set
474
    # Filter by authtypecode if set
472
    if ($search->{authtypecode}) {
475
    if ( $search->{authtypecode} ) {
473
        $elastic_query->{bool}->{filter} = {
476
        push @filters, { term => { "authtype.raw" => $search->{authtypecode} } };
474
            term => {
477
    }
475
                "authtype.raw" => $search->{authtypecode}
478
479
    # Filter by establishing headings if set
480
    # terms supports an array of values
481
    if ( $search->{est_headings} ) {
482
        push @filters, {
483
            terms => {
484
                "kind-of-record.raw" => [ 'a', 'f', '|' ],
476
            }
485
            }
477
        };
486
        };
478
    }
487
    }
479
488
489
    $elastic_query->{bool}->{filter} = \@filters;
490
480
    my $query = {
491
    my $query = {
481
        query => $elastic_query
492
        query => $elastic_query
482
    };
493
    };
Lines 575-581 our $thesaurus_to_value = { Link Here
575
586
576
sub build_authorities_query_compat {
587
sub build_authorities_query_compat {
577
    my ( $self, $marclist, $and_or, $excluding, $operator, $value,
588
    my ( $self, $marclist, $and_or, $excluding, $operator, $value,
578
        $authtypecode, $orderby )
589
        $authtypecode, $orderby, $est_headings )
579
      = @_;
590
      = @_;
580
591
581
    # This turns the old-style many-options argument form into a more
592
    # This turns the old-style many-options argument form into a more
Lines 619-624 sub build_authorities_query_compat { Link Here
619
    my %search = (
630
    my %search = (
620
        searches     => \@searches,
631
        searches     => \@searches,
621
        authtypecode => $authtypecode,
632
        authtypecode => $authtypecode,
633
        est_headings => $est_headings,
622
    );
634
    );
623
    $search{sort} = \%sort if %sort;
635
    $search{sort} = \%sort if %sort;
624
    my $query = $self->build_authorities_query( \%search );
636
    my $query = $self->build_authorities_query( \%search );
(-)a/Koha/SearchEngine/Zebra/QueryBuilder.pm (+1 lines)
Lines 103-108 sub build_authorities_query { Link Here
103
        value        => $_[4],
103
        value        => $_[4],
104
        authtypecode => $_[5],
104
        authtypecode => $_[5],
105
        orderby      => $_[6],
105
        orderby      => $_[6],
106
        est_headings => $_[7],
106
    };
107
    };
107
}
108
}
108
109
(-)a/Koha/SearchEngine/Zebra/Search.pm (-1 / +1 lines)
Lines 105-111 sub search_auth_compat { Link Here
105
    my @params = (
105
    my @params = (
106
        @{$q}{ 'marclist', 'and_or', 'excluding', 'operator', 'value' },
106
        @{$q}{ 'marclist', 'and_or', 'excluding', 'operator', 'value' },
107
        $startfrom - 1,
107
        $startfrom - 1,
108
        $resperpage, @{$q}{ 'authtypecode', 'orderby' }, $skipmetadata
108
        $resperpage, @{$q}{ 'authtypecode', 'orderby' }, $skipmetadata, @{$q}{'est_headings'}
109
    );
109
    );
110
    C4::AuthoritiesMarc::SearchAuthorities(@params);
110
    C4::AuthoritiesMarc::SearchAuthorities(@params);
111
}
111
}
(-)a/authorities/auth_finder.pl (-1 / +4 lines)
Lines 67-72 if ( $op eq "do_search" ) { Link Here
67
    my $orderby        = $query->param('orderby')        || '';
67
    my $orderby        = $query->param('orderby')        || '';
68
    my $startfrom      = $query->param('startfrom')      || 0;
68
    my $startfrom      = $query->param('startfrom')      || 0;
69
    my $resultsperpage = $query->param('resultsperpage') || 20;
69
    my $resultsperpage = $query->param('resultsperpage') || 20;
70
    my $est_headings   = $query->param('est_headings')   || undef;
70
71
71
    my $builder = Koha::SearchEngine::QueryBuilder->new(
72
    my $builder = Koha::SearchEngine::QueryBuilder->new(
72
        { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
73
        { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
Lines 74-81 if ( $op eq "do_search" ) { Link Here
74
        { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
75
        { index => $Koha::SearchEngine::AUTHORITIES_INDEX } );
75
    my $search_query = $builder->build_authorities_query_compat(
76
    my $search_query = $builder->build_authorities_query_compat(
76
        \@marclist, \@and_or, \@excluding, \@operator,
77
        \@marclist, \@and_or, \@excluding, \@operator,
77
        \@value, $authtypecode, $orderby
78
        \@value, $authtypecode, $orderby, $est_headings
78
    );
79
    );
80
79
    $template->param( search_query => $search_query ) if C4::Context->preference('DumpSearchQueryTemplate');
81
    $template->param( search_query => $search_query ) if C4::Context->preference('DumpSearchQueryTemplate');
80
    my $offset = $startfrom * $resultsperpage;
82
    my $offset = $startfrom * $resultsperpage;
81
    my ( $results, $total ) =
83
    my ( $results, $total ) =
Lines 176-181 if ( $op eq "do_search" ) { Link Here
176
        operator_main    => ( @operator > 1 && $operator[1] ) ? $operator[1] : '',
178
        operator_main    => ( @operator > 1 && $operator[1] ) ? $operator[1] : '',
177
        operator_match   => ( @operator > 2 && $operator[2] ) ? $operator[2] : '',
179
        operator_match   => ( @operator > 2 && $operator[2] ) ? $operator[2] : '',
178
        operator_any     => ( @operator > 3 && $operator[3] ) ? $operator[3] : '',
180
        operator_any     => ( @operator > 3 && $operator[3] ) ? $operator[3] : '',
181
        est_headings     => $est_headings,
179
    );
182
    );
180
}
183
}
181
else {
184
else {
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/auth-finder-search.inc (+15 lines)
Lines 117-122 Link Here
117
                    <input id="value_any" style="width:400px;" type="text" name="value_any" value="[% value_any | html %]" />
117
                    <input id="value_any" style="width:400px;" type="text" name="value_any" value="[% value_any | html %]" />
118
                    <div id="yvaluecontainermarclist"></div>
118
                    <div id="yvaluecontainermarclist"></div>
119
                </li>
119
                </li>
120
                <li>
121
                    <label for="est_headings">Established headings only: </label>
122
                    <select name="est_headings" id="est_headings">
123
                        [% IF !est_headings AND op == 'do_search' %]
124
                            <option value="1">Yes</option>
125
                            <option value="" selected="selected">No</option>
126
                        [% ELSIF Koha.Preference('LinkEstablishedHeadings') OR est_headings %]
127
                            <option value="1" selected="selected">Yes</option>
128
                            <option value="">No</option>
129
                        [% ELSE %]
130
                            <option value="1">Yes</option>
131
                            <option value="" selected="selected">No</option>
132
                        [% END %]
133
                    </select>
134
                </li>
120
        <li>
135
        <li>
121
        <label for="orderby">Sort by: </label>
136
        <label for="orderby">Sort by: </label>
122
        <select name="orderby" id="orderby">
137
        <select name="orderby" id="orderby">
(-)a/t/Koha/SearchEngine/Zebra/QueryBuilder.t (-1 / +2 lines)
Lines 27-33 subtest 'build_authorities_query' => sub { Link Here
27
27
28
    my @test_search = (
28
    my @test_search = (
29
        ['mainmainentry'], ['and'], [''], ['contains'], ['any'], '',
29
        ['mainmainentry'], ['and'], [''], ['contains'], ['any'], '',
30
        'HeadingAsc'
30
        'HeadingAsc',      1
31
    );
31
    );
32
    my $expected_result = {
32
    my $expected_result = {
33
        marclist     => ['mainmainentry'],
33
        marclist     => ['mainmainentry'],
Lines 37-42 subtest 'build_authorities_query' => sub { Link Here
37
        value        => ['any'],
37
        value        => ['any'],
38
        authtypecode => '',
38
        authtypecode => '',
39
        orderby      => 'HeadingAsc',
39
        orderby      => 'HeadingAsc',
40
        est_headings => 1,
40
    };
41
    };
41
    my $built_search =
42
    my $built_search =
42
      Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search );
43
      Koha::SearchEngine::Zebra::QueryBuilder->build_authorities_query( @test_search );
(-)a/t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t (-4 / +20 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 => 73;
109
109
110
    my $qb;
110
    my $qb;
111
111
Lines 192-204 subtest 'build_authorities_query_compat() tests' => sub { Link Here
192
    );
192
    );
193
193
194
    # Authorities type
194
    # Authorities type
195
    $query = $qb->build_authorities_query_compat( [ 'mainentry' ],  undef, undef, ['contains'], [$search_term], 'AUTH_TYPE', 'asc' );
195
    $query = $qb->build_authorities_query_compat(
196
        ['mainentry'], undef, undef, ['contains'], [$search_term], 'AUTH_TYPE',
197
        'asc'
198
    );
196
    is_deeply(
199
    is_deeply(
197
        $query->{query}->{bool}->{filter},
200
        $query->{query}->{bool}->{filter},
198
        { term => { 'authtype.raw' => 'AUTH_TYPE' } },
201
        [ { term => { 'authtype.raw' => 'AUTH_TYPE' } } ],
199
        "authorities type code is used as filter"
202
        "authorities type code is used as filter"
200
    );
203
    );
201
204
205
    # established headings filter, authtype filter is still there
206
    $query = $qb->build_authorities_query_compat(
207
        ['mainentry'], undef, undef, ['contains'], [$search_term], 'AUTH_TYPE',
208
        'asc', 1
209
    );
210
    is_deeply(
211
        $query->{query}->{bool}->{filter},
212
        [
213
            { term  => { 'authtype.raw'       => 'AUTH_TYPE' } },
214
            { terms => { 'kind-of-record.raw' => [ 'a', 'f', '|' ] } }
215
        ],
216
        "both kind-of-record code and authorities type code are used as filters"
217
    );
218
202
    # Authorities marclist check
219
    # Authorities marclist check
203
    warning_like {
220
    warning_like {
204
        $query = $qb->build_authorities_query_compat( [ 'tomas','mainentry' ],  undef, undef, ['contains'], [$search_term,$search_term], 'AUTH_TYPE', 'asc' )
221
        $query = $qb->build_authorities_query_compat( [ 'tomas','mainentry' ],  undef, undef, ['contains'], [$search_term,$search_term], 'AUTH_TYPE', 'asc' )
205
- 

Return to bug 36616