2 # WARNING: 4-character tab stops here
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
30 use C4::AuthoritiesMarc;
32 use C4::Search::History;
34 use Koha::Authority::Types;
35 use Koha::SearchEngine::Search;
36 use Koha::SearchEngine::QueryBuilder;
39 my $op = $query->param('op') || '';
40 my $authtypecode = $query->param('authtypecode') || '';
41 my $dbh = C4::Context->dbh;
43 my $startfrom = $query->param('startfrom');
44 my $authid = $query->param('authid');
45 $startfrom = 0 if ( !defined $startfrom );
46 my ( $template, $loggedinuser, $cookie );
49 my $authority_types = Koha::Authority::Types->search({}, { order_by => ['authtypetext']});
51 if ( $op eq "do_search" ) {
52 my @marclist = $query->multi_param('marclist');
53 my @and_or = $query->multi_param('and_or');
54 my @excluding = $query->multi_param('excluding');
55 my @operator = $query->multi_param('operator');
56 my $orderby = $query->param('orderby');
57 my @value = $query->multi_param('value');
60 $resultsperpage = $query->param('resultsperpage');
61 $resultsperpage = 20 if ( !defined $resultsperpage );
63 my $builder = Koha::SearchEngine::QueryBuilder->new();
64 my $searcher = Koha::SearchEngine::Search->new({index => 'authorities'});
65 my $search_query = $builder->build_authorities_query_compat( \@marclist, \@and_or,
66 \@excluding, \@operator, \@value, $authtypecode, $orderby );
68 # die Dumper(\@marclist, \@and_or,
69 # \@excluding, \@operator, \@value, $authtypecode, $orderby, $query);
70 # The searchengine API expects pages to start at page 1
71 $startfrom = $startfrom // 0;
72 my ( $results, $total ) =
73 $searcher->search_auth_compat( $search_query, $startfrom+1, $resultsperpage );
74 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
76 template_name => "opac-authoritiessearchresultlist.tt",
84 # multi page display gestion
86 my $displayprev = $startfrom;
88 if ( ( $total - ( ( $startfrom + 1 ) * ($resultsperpage) ) ) > 0 ) {
93 { term => "marclist", val => $marclist[0] },
94 { term => "and_or", val => $and_or[0] },
95 { term => "excluding", val => $excluding[0] },
96 { term => "operator", val => $operator[0] },
97 { term => "value", val => $value[0] },
102 if ( $total > $resultsperpage ) {
103 for ( my $i = 1 ; $i < $total / $resultsperpage + 1 ; $i++ ) {
106 ( $startfrom == ( $i - 1 ) ) && ( $highlight = 1 );
110 highlight => $highlight,
111 searchdata => \@field_data,
112 startfrom => ( $i - 1 )
118 my $from = $startfrom * $resultsperpage + 1;
121 if ( $total < ( ( $startfrom + 1 ) * $resultsperpage ) ) {
125 $to = ( ( $startfrom + 1 ) * $resultsperpage );
127 unless (C4::Context->preference('OPACShowUnusedAuthorities')) {
128 # TODO implement usage counts
129 # my @usedauths = grep { $_->{used} > 0 } @$results;
130 # $results = \@usedauths;
133 # Opac search history
134 if (C4::Context->preference('EnableOpacSearchHistory')) {
135 unless ( $startfrom ) {
136 my $path_info = $query->url(-path_info=>1);
137 my $query_cgi_history = $query->url(-query=>1);
138 $query_cgi_history =~ s/^$path_info\?//;
139 $query_cgi_history =~ s/;/&/g;
141 unless ( $loggedinuser ) {
142 my $new_search = C4::Search::History::add_to_session({
144 query_desc => $value[0],
145 query_cgi => $query_cgi_history,
150 # To the session (the user is logged in)
151 C4::Search::History::add({
152 userid => $loggedinuser,
153 sessionid => $query->cookie("CGISESSID"),
154 query_desc => $value[0],
155 query_cgi => $query_cgi_history,
163 $template->param( result => $results ) if $results;
164 $template->param( orderby => $orderby );
166 startfrom => $startfrom,
167 displaynext => $displaynext,
168 displayprev => $displayprev,
169 resultsperpage => $resultsperpage,
170 startfromnext => $startfrom + 1,
171 startfromprev => $startfrom - 1,
172 searchdata => \@field_data,
173 countfuzzy => !(C4::Context->preference('OPACShowUnusedAuthorities')),
177 resultcount => scalar @$results,
178 numbers => \@numbers,
179 authtypecode => $authtypecode,
180 authtypetext => $authority_types->find($authtypecode)->authtypetext,
181 isEDITORS => $authtypecode eq 'EDITORS',
186 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
188 template_name => "opac-authorities-home.tt",
191 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
199 authority_types => $authority_types,
200 authtypecode => $authtypecode,
204 output_html_with_http_headers $query, $cookie, $template->output;