Respect BiblioDefaultView when search returns only 1 result & jump directly to the...
[koha.git] / opac / opac-search.pl
1 #!/usr/bin/perl
2 # Script to perform searching
3 # Mostly copied from search.pl, see POD there
4 use strict;            # always use
5
6 ## STEP 1. Load things that are used in both search page and
7 # results page and decide which template to load, operations 
8 # to perform, etc.
9 ## load Koha modules
10 use C4::Context;
11 use C4::Output;
12 use C4::Auth;
13 use C4::Search;
14 use C4::Biblio;  # GetBiblioData
15 use C4::Koha;
16 use C4::Tags qw(get_tags);
17 use POSIX qw(ceil floor);
18 use C4::Branch; # GetBranches
19
20 # create a new CGI object
21 # FIXME: no_undef_params needs to be tested
22 use CGI qw('-no_undef_params');
23 my $cgi = new CGI;
24
25 BEGIN {
26         if (C4::Context->preference('BakerTaylorEnabled')) {
27                 require C4::External::BakerTaylor;
28                 import C4::External::BakerTaylor qw(&image_url &link_url);
29         }
30 }
31
32 my ($template,$borrowernumber,$cookie);
33
34 # decide which template to use
35 my $template_name;
36 my $template_type;
37 my @params = $cgi->param("limit");
38
39 my $build_grouped_results = C4::Context->preference('OPACGroupResults');
40 if  ($cgi->param("format") =~ /(rss|atom|opensearchdescription)/) {
41         $template_name = 'opac-opensearch.tmpl';
42 }
43 elsif ($build_grouped_results) {
44     $template_name = 'opac-results-grouped.tmpl';
45 }
46 elsif ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) ) {
47         $template_name = 'opac-results.tmpl';
48 }
49 else {
50     $template_name = 'opac-advsearch.tmpl';
51     $template_type = 'advsearch';
52 }
53 # load the template
54 ($template, $borrowernumber, $cookie) = get_template_and_user({
55     template_name => $template_name,
56     query => $cgi,
57     type => "opac",
58     authnotrequired => 1,
59     }
60 );
61 if ($cgi->param("format") eq 'rss2') {
62         $template->param("rss2" => 1);
63 }
64 elsif ($cgi->param("format") eq 'atom') {
65         $template->param("atom" => 1);
66 }
67 elsif ($cgi->param("format") eq 'opensearchdescription') {
68         $template->param("opensearchdescription" => 1);
69 }
70 if (C4::Context->preference("marcflavour") eq "UNIMARC" ) {
71     $template->param('UNIMARC' => 1);
72 }
73
74 if (C4::Context->preference('BakerTaylorEnabled')) {
75         $template->param(
76                 BakerTaylorEnabled  => 1,
77                 BakerTaylorImageURL => &image_url(),
78                 BakerTaylorLinkURL  => &link_url(),
79                 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
80         );
81 }
82 if (C4::Context->preference('TagsEnabled')) {
83         $template->param(TagsEnabled => 1);
84         foreach (qw(TagsShowOnList TagsInputOnList)) {
85                 C4::Context->preference($_) and $template->param($_ => 1);
86         }
87 }
88
89 ## URI Re-Writing
90 # Deprecated, but preserved because it's interesting :-)
91 # The same thing can be accomplished with mod_rewrite in
92 # a more elegant way
93 #                  
94 #my $rewrite_flag;
95 #my $uri = $cgi->url(-base => 1);
96 #my $relative_url = $cgi->url(-relative=>1);
97 #$uri.="/".$relative_url."?";
98 #warn "URI:$uri";
99 #my @cgi_params_list = $cgi->param();
100 #my $url_params = $cgi->Vars;
101 #
102 #for my $each_param_set (@cgi_params_list) {
103 #    $uri.= join "",  map "\&$each_param_set=".$_, split("\0",$url_params->{$each_param_set}) if $url_params->{$each_param_set};
104 #}
105 #warn "New URI:$uri";
106 # Only re-write a URI if there are params or if it already hasn't been re-written
107 #unless (($cgi->param('r')) || (!$cgi->param()) ) {
108 #    print $cgi->redirect(     -uri=>$uri."&r=1",
109 #                            -cookie => $cookie);
110 #    exit;
111 #}
112
113 # load the branches
114 my $branches = GetBranches();
115 my @branch_loop;
116
117 for my $branch_hash (sort keys %$branches) {
118     push @branch_loop, {value => "$branch_hash" , branchname => $branches->{$branch_hash}->{'branchname'}, };
119 }
120
121 my $categories = GetBranchCategories(undef,'searchdomain');
122
123 $template->param(branchloop => \@branch_loop, searchdomainloop => $categories);
124
125 # load the itemtypes
126 my $itemtypes = GetItemTypes;
127 my @itemtypesloop;
128 my $selected=1;
129 my $cnt;
130 my $imgdir = getitemtypeimagesrc('opac');
131
132 foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) {
133     my %row =(  number=>$cnt++,
134                 imageurl=> $itemtypes->{$thisitemtype}->{'imageurl'}?($imgdir."/".$itemtypes->{$thisitemtype}->{'imageurl'}):"",
135                 code => $thisitemtype,
136                 selected => $selected,
137                 description => $itemtypes->{$thisitemtype}->{'description'},
138                 count5 => $cnt % 4,
139             );
140     $selected = 0 if ($selected) ;
141     push @itemtypesloop, \%row;
142 }
143 $template->param(itemtypeloop => \@itemtypesloop);
144
145 # # load the itypes (Called item types in the template -- just authorized values for searching)
146 # my ($itypecount,@itype_loop) = GetCcodes();
147 # $template->param(itypeloop=>\@itype_loop,);
148
149 # The following should only be loaded if we're bringing up the advanced search template
150 if ( $template_type eq 'advsearch' ) {
151
152     # load the servers (used for searching -- to do federated searching, etc.)
153     my $primary_servers_loop;# = displayPrimaryServers();
154     $template->param(outer_servers_loop =>  $primary_servers_loop,);
155     
156     my $secondary_servers_loop;# = displaySecondaryServers();
157     $template->param(outer_sup_servers_loop => $secondary_servers_loop,);
158     
159     # determine what to display next to the search boxes (ie, boolean option
160     # shouldn't appear on the first one, scan indexes should, adding a new
161     # box should only appear on the last, etc.
162     my @search_boxes_array;
163     my $search_boxes_count = C4::Context->preference("OPACAdvSearchInputCount") | 3; # FIXME: should be a syspref
164     for (my $i=1;$i<=$search_boxes_count;$i++) {
165         # if it's the first one, don't display boolean option, but show scan indexes
166         if ($i==1) {
167             push @search_boxes_array,
168                 {
169                 scan_index => 1,
170                 };
171         
172         }
173         # if it's the last one, show the 'add field' box
174         elsif ($i==$search_boxes_count) {
175             push @search_boxes_array,
176                 {
177                 boolean => 1,
178                 add_field => 1,
179                 };
180         }
181         else {
182             push @search_boxes_array,
183                 {
184                 boolean => 1,
185                 };
186         }
187
188     }
189     $template->param(uc(C4::Context->preference("marcflavour")) => 1,
190                                           advsearch => 1,
191                       search_boxes_loop => \@search_boxes_array);
192
193 # use the global setting by default
194         if ( C4::Context->preference("expandedSearchOption") == 1) {
195                 $template->param( expanded_options => C4::Context->preference("expandedSearchOption") );
196         }
197         # but let the user override it
198         if ( ($cgi->param('expanded_options') == 0) || ($cgi->param('expanded_options') == 1 ) ) {
199         $template->param( expanded_options => $cgi->param('expanded_options'));
200         }
201
202     output_html_with_http_headers $cgi, $cookie, $template->output;
203     exit;
204 }
205
206 ### OK, if we're this far, we're performing an actual search
207
208 # Fetch the paramater list as a hash in scalar context:
209 #  * returns paramater list as tied hash ref
210 #  * we can edit the values by changing the key
211 #  * multivalued CGI paramaters are returned as a packaged string separated by "\0" (null)
212 my $params = $cgi->Vars;
213 my $tag;
214 $tag = $params->{tag} if $params->{tag};
215
216 # Params that can have more than one value
217 # sort by is used to sort the query
218 # in theory can have more than one but generally there's just one
219 my @sort_by;
220 my $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') 
221     if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
222
223 @sort_by = split("\0",$params->{'sort_by'}) if $params->{'sort_by'};
224 $sort_by[0] = $default_sort_by unless $sort_by[0];
225 foreach my $sort (@sort_by) {
226     $template->param($sort => 1);
227 }
228 $template->param('sort_by' => $sort_by[0]);
229
230 # Use the servers defined, or just search our local catalog(default)
231 my @servers;
232 @servers = split("\0",$params->{'server'}) if $params->{'server'};
233 unless (@servers) {
234     #FIXME: this should be handled using Context.pm
235     @servers = ("biblioserver");
236     # @servers = C4::Context->config("biblioserver");
237 }
238
239 # operators include boolean and proximity operators and are used
240 # to evaluate multiple operands
241 my @operators;
242 @operators = split("\0",$params->{'op'}) if $params->{'op'};
243
244 # indexes are query qualifiers, like 'title', 'author', etc. They
245 # can be single or multiple parameters separated by comma: kw,right-Truncation 
246 my @indexes = split("\0",$params->{'idx'});
247
248 # if a simple index (only one)  display the index used in the top search box
249 if ($indexes[0] && !$indexes[1]) {
250     $template->param("ms_".$indexes[0] => 1);
251 }
252 # an operand can be a single term, a phrase, or a complete ccl query
253 my @operands;
254 @operands = split("\0",$params->{'q'}) if $params->{'q'};
255
256 # if a simple search, display the value in the search box
257 if ($operands[0] && !$operands[1]) {
258     $template->param(ms_value => $operands[0]);
259 }
260
261 # limits are use to limit to results to a pre-defined category such as branch or language
262 my @limits;
263 @limits = split("\0",$params->{'limit'}) if $params->{'limit'};
264
265 if($params->{'multibranchlimit'}) {
266 push @limits, join(" or ", map { "branch: $_ "}  @{GetBranchesInCategory($params->{'multibranchlimit'})}) ;
267 }
268
269 my $available;
270 foreach my $limit(@limits) {
271     if ($limit =~/available/) {
272         $available = 1;
273     }
274 }
275 $template->param(available => $available);
276
277 # append year limits if they exist
278 if ($params->{'limit-yr'}) {
279     if ($params->{'limit-yr'} =~ /\d{4}-\d{4}/) {
280         my ($yr1,$yr2) = split(/-/, $params->{'limit-yr'});
281         push @limits, "yr,st-numeric,ge=$yr1 and yr,st-numeric,le=$yr2";
282     }
283     elsif ($params->{'limit-yr'} =~ /\d{4}/) {
284         push @limits, "yr,st-numeric=$params->{'limit-yr'}";
285     }
286     else {
287         #FIXME: Should return a error to the user, incorect date format specified
288     }
289 }
290
291 # Params that can only have one value
292 my $scan = $params->{'scan'};
293 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
294 my $results_per_page = $params->{'count'} || $count;
295 my $offset = $params->{'offset'} || 0;
296 my $page = $cgi->param('page') || 1;
297 $offset = ($page-1)*$results_per_page if $page>1;
298 my $hits;
299 my $expanded_facet = $params->{'expand'};
300
301 # Define some global variables
302 my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type);
303
304 my @results;
305
306 ## I. BUILD THE QUERY
307 ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$stopwords_removed,$query_type) = buildQuery(\@operators,\@operands,\@indexes,\@limits,\@sort_by);
308
309 sub _input_cgi_parse ($) { 
310     my @elements;
311     for my $this_cgi ( split('&',shift) ) {
312         next unless $this_cgi;
313         $this_cgi =~ /(.*)=(.*)/;
314         push @elements, { input_name => $1, input_value => $2 };
315     }
316     return @elements;
317 }
318
319 ## parse the query_cgi string and put it into a form suitable for <input>s
320 my @query_inputs = _input_cgi_parse($query_cgi);
321 $template->param ( QUERY_INPUTS => \@query_inputs );
322
323 ## parse the limit_cgi string and put it into a form suitable for <input>s
324 my @limit_inputs = _input_cgi_parse($limit_cgi);
325
326 # add OPAC 'hidelostitems'
327 if (C4::Context->preference('hidelostitems') == 1) {
328     # either lost ge 0 or no value in the lost register
329     $query ="($query) and ( (lost,st-numeric <= 0) or ( allrecords,AlwaysMatches='' not lost,AlwaysMatches='') )";
330 }
331
332 # add OPAC suppression - requires at least one item indexed with Suppress
333 if (C4::Context->preference('OpacSuppression')) {
334     $query = "($query) not Suppress=1";
335 }
336
337 $template->param ( LIMIT_INPUTS => \@limit_inputs );
338
339 ## II. DO THE SEARCH AND GET THE RESULTS
340 my $total; # the total results for the whole set
341 my $facets; # this object stores the faceted results that display on the left-hand of the results page
342 my @results_array;
343 my $results_hashref;
344
345 if ($tag) {
346         my $taglist = get_tags({term=>$tag});
347         $results_hashref->{biblioserver}->{hits} = scalar (@$taglist);
348         my @biblist  = (map {GetBiblioData($_->{biblionumber})} @$taglist);
349         my @marclist = (map {$_->{marc}} @biblist );
350         $DEBUG and printf STDERR "taglist (%s biblionumber)\nmarclist (%s records)\n", scalar(@$taglist), scalar(@marclist);
351         $results_hashref->{biblioserver}->{RECORDS} = \@marclist;
352         # FIXME: tag search and standard search should work together, not exclusively
353         # FIXME: No facets for tags search.
354 }
355 elsif (C4::Context->preference('NoZebra')) {
356     eval {
357         ($error, $results_hashref, $facets) = NZgetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
358     };
359 } elsif ($build_grouped_results) {
360     eval {
361         ($error, $results_hashref, $facets) = C4::Search::pazGetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
362     };
363 } else {
364     eval {
365         ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan);
366     };
367 }
368 # use Data::Dumper; print STDERR "-" x 25, "\n", Dumper($results_hashref);
369 if ($@ || $error) {
370     $template->param(query_error => $error.$@);
371     output_html_with_http_headers $cgi, $cookie, $template->output;
372     exit;
373 }
374
375 # At this point, each server has given us a result set
376 # now we build that set for template display
377 my @sup_results_array;
378 for (my $i=0;$i<=@servers;$i++) {
379     my $server = $servers[$i];
380     if ($server =~/biblioserver/) { # this is the local bibliographic server
381         $hits = $results_hashref->{$server}->{"hits"};
382         my $page = $cgi->param('page') || 0;
383         my @newresults;
384         if ($build_grouped_results) {
385             foreach my $group (@{ $results_hashref->{$server}->{"GROUPS"} }) {
386                 # because pazGetRecords handles retieving only the records
387                 # we want as specified by $offset and $results_per_page,
388                 # we need to set the offset parameter of searchResults to 0
389                 my @group_results = searchResults( $query_desc, $group->{'group_count'},$results_per_page, 0,
390                                                    @{ $group->{"RECORDS"} });
391                 push @newresults, { group_label => $group->{'group_label'}, GROUP_RESULTS => \@group_results };
392             }
393         } else {
394             @newresults = searchResults( $query_desc,$hits,$results_per_page,$offset,@{$results_hashref->{$server}->{"RECORDS"}});
395         }
396                 my $tag_quantity;
397                 if (C4::Context->preference('TagsEnabled') and
398                         $tag_quantity = C4::Context->preference('TagsShowOnList')) {
399                         foreach (@newresults) {
400                                 my $bibnum = $_->{biblionumber} or next;
401                                 $_ ->{'TagLoop'} = get_tags({biblionumber=>$bibnum, 'sort'=>'-weight',
402                                                                                 limit=>$tag_quantity });
403                         }
404                 }
405                 foreach (@newresults) {
406                         my $clean = $_->{isbn} or next;
407                         unless (
408                                 $clean =~ /\b(\d{13})\b/ or
409                                 $clean =~ /\b(\d{10})\b/ or 
410                                 $clean =~ /\b(\d{9}X)\b/i
411                         ) {
412                                 next;
413                         }
414                         $_ ->{'clean_isbn'} = $1;
415                 }
416         $total = $total + $results_hashref->{$server}->{"hits"};
417         ## If there's just one result, redirect to the detail page
418         if ($total == 1) {         
419             my $biblionumber=@newresults[0]->{biblionumber};
420             if (C4::Context->preference('BiblioDefaultView') eq 'isbd') {
421                 print $cgi->redirect("/cgi-bin/koha/opac-ISBDdetail.pl?biblionumber=$biblionumber");
422             } elsif  (C4::Context->preference('BiblioDefaultView') eq 'marc') {
423                 print $cgi->redirect("/cgi-bin/koha/opac-MARCdetail.pl?biblionumber=$biblionumber");
424             } else {
425                 print $cgi->redirect("/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber");
426             } 
427             exit;
428         }
429         if ($hits) {
430             $template->param(total => $hits);
431             my $limit_cgi_not_availablity = $limit_cgi;
432             $limit_cgi_not_availablity =~ s/&limit=available//g;
433             $template->param(limit_cgi_not_availablity => $limit_cgi_not_availablity);
434             $template->param(limit_cgi => $limit_cgi);
435             $template->param(query_cgi => $query_cgi);
436             $template->param(query_desc => $query_desc);
437             $template->param(limit_desc => $limit_desc);
438             if ($query_desc || $limit_desc) {
439                 $template->param(searchdesc => 1);
440             }
441             $template->param(stopwords_removed => "@$stopwords_removed") if $stopwords_removed;
442             $template->param(results_per_page =>  $results_per_page);
443             $template->param(SEARCH_RESULTS => \@newresults,
444                                 OPACItemsResultsDisplay => (C4::Context->preference("OPACItemsResultsDisplay") eq "itemdetails"?1:0),
445                             );
446             ## Build the page numbers on the bottom of the page
447             my @page_numbers;
448             # total number of pages there will be
449             my $pages = ceil($hits / $results_per_page);
450             # default page number
451             my $current_page_number = 1;
452             $current_page_number = ($offset / $results_per_page + 1) if $offset;
453             my $previous_page_offset = $offset - $results_per_page unless ($offset - $results_per_page <0);
454             my $next_page_offset = $offset + $results_per_page;
455             # If we're within the first 10 pages, keep it simple
456             #warn "current page:".$current_page_number;
457             if ($current_page_number < 10) {
458                 # just show the first 10 pages
459                 # Loop through the pages
460                 my $pages_to_show = 10;
461                 $pages_to_show = $pages if $pages<10;
462                 for ($i=1; $i<=$pages_to_show;$i++) {
463                     # the offset for this page
464                     my $this_offset = (($i*$results_per_page)-$results_per_page);
465                     # the page number for this page
466                     my $this_page_number = $i;
467                     # it should only be highlighted if it's the current page
468                     my $highlight = 1 if ($this_page_number == $current_page_number);
469                     # put it in the array
470                     push @page_numbers, { offset => $this_offset, pg => $this_page_number, highlight => $highlight, sort_by => join " ",@sort_by };
471                                 
472                 }
473                         
474             }
475             # now, show twenty pages, with the current one smack in the middle
476             else {
477                 for ($i=$current_page_number; $i<=($current_page_number + 20 );$i++) {
478                     my $this_offset = ((($i-9)*$results_per_page)-$results_per_page);
479                     my $this_page_number = $i-9;
480                     my $highlight = 1 if ($this_page_number == $current_page_number);
481                     if ($this_page_number <= $pages) {
482                         push @page_numbers, { offset => $this_offset, pg => $this_page_number, highlight => $highlight, sort_by => join " ",@sort_by };
483                     }
484                 }
485                         
486             }
487             $template->param(   PAGE_NUMBERS => \@page_numbers,
488                                 previous_page_offset => $previous_page_offset) unless $pages < 2;
489             $template->param(next_page_offset => $next_page_offset) unless $pages eq $current_page_number;
490          }
491         # no hits
492         else {
493             $template->param(searchdesc => 1,query_desc => $query_desc,limit_desc => $limit_desc);
494         }
495     } # end of the if local
496     # asynchronously search the authority server
497     elsif ($server =~/authorityserver/) { # this is the local authority server
498         my @inner_sup_results_array;
499         for my $sup_record ( @{$results_hashref->{$server}->{"RECORDS"}} ) {
500             my $marc_record_object = MARC::Record->new_from_usmarc($sup_record);
501             my $title_field = $marc_record_object->field(100);
502              warn "Authority Found: ".$marc_record_object->as_formatted();
503             push @inner_sup_results_array, {
504                 'title' => $title_field->subfield('a'),
505                 'link' => "&amp;idx=an&amp;q=".$marc_record_object->field('001')->as_string(),
506             };
507         }
508         my $servername = $server;
509         push @sup_results_array, {  servername => $servername,
510                                     inner_sup_results_loop => \@inner_sup_results_array} if @inner_sup_results_array;
511     }
512     # FIXME: can add support for other targets as needed here
513     $template->param(           outer_sup_results_loop => \@sup_results_array);
514 } #/end of the for loop
515 #$template->param(FEDERATED_RESULTS => \@results_array);
516
517 $template->param(
518             #classlist => $classlist,
519             total => $total,
520             opacfacets => 1,
521             facets_loop => $facets,
522             scan => $scan,
523             search_error => $error,
524 );
525
526 if ($query_desc || $limit_desc) {
527     $template->param(searchdesc => 1);
528 }
529
530 ## Now let's find out if we have any supplemental data to show the user
531 #  and in the meantime, save the current query for statistical purposes, etc.
532 my $koha_spsuggest; # a flag to tell if we've got suggestions coming from Koha
533 my @koha_spsuggest; # place we store the suggestions to be returned to the template as LOOP
534 my $phrases = $query_desc;
535 my $ipaddress;
536
537 if ( C4::Context->preference("kohaspsuggest") ) {
538         my ($suggest_host, $suggest_dbname, $suggest_user, $suggest_pwd) = split(':', C4::Context->preference("kohaspsuggest"));
539         eval {
540             my $koha_spsuggest_dbh;
541             # FIXME: this needs to be moved to Context.pm
542             eval {
543                 $koha_spsuggest_dbh=DBI->connect("DBI:mysql:$suggest_dbname:$suggest_host","$suggest_user","$suggest_pwd");
544             };
545             if ($@) { 
546                 warn "can't connect to spsuggest db";
547             }
548             else {
549                 my $koha_spsuggest_insert = "INSERT INTO phrase_log(phr_phrase,phr_resultcount,phr_ip) VALUES(?,?,?)";
550                 my $koha_spsuggest_query = "SELECT display FROM distincts WHERE strcmp(soundex(suggestion), soundex(?)) = 0 order by soundex(suggestion) limit 0,5";
551                 my $koha_spsuggest_sth = $koha_spsuggest_dbh->prepare($koha_spsuggest_query);
552                 $koha_spsuggest_sth->execute($phrases);
553                 while (my $spsuggestion = $koha_spsuggest_sth->fetchrow_array) {
554                     $spsuggestion =~ s/(:|\/)//g;
555                     my %line;
556                     $line{spsuggestion} = $spsuggestion;
557                     push @koha_spsuggest,\%line;
558                     $koha_spsuggest = 1;
559                 }
560
561                 # Now save the current query
562                 $koha_spsuggest_sth=$koha_spsuggest_dbh->prepare($koha_spsuggest_insert);
563                 #$koha_spsuggest_sth->execute($phrases,$results_per_page,$ipaddress);
564                 $koha_spsuggest_sth->finish;
565
566                 $template->param( koha_spsuggest => $koha_spsuggest ) unless $hits;
567                 $template->param( SPELL_SUGGEST => \@koha_spsuggest,
568                 );
569             }
570     };
571     if ($@) {
572             warn "Kohaspsuggest failure:".$@;
573     }
574 }
575
576 # VI. BUILD THE TEMPLATE
577 output_html_with_http_headers $cgi, $cookie, $template->output;