Bug 23523: (follow-up) Adjust tests for new expectations
[srvgit] / opac / opac-search.pl
index a18d509..ea78ca0 100755 (executable)
@@ -118,6 +118,9 @@ else {
     $template_name = 'opac-advsearch.tt';
     $template_type = 'advsearch';
 }
+
+$format = 'rss' if $format =~ /^rss2?$/;
+
 # load the template
 ($template, $borrowernumber, $cookie) = get_template_and_user({
     template_name => $template_name,
@@ -142,7 +145,7 @@ if($cgi->cookie("bib_list")){
     @cart_list = split(/\//, $cart_list);
 }
 
-if ($format eq 'rss2' or $format eq 'opensearchdescription' or $format eq 'atom') {
+if ($format eq 'rss' or $format eq 'opensearchdescription' or $format eq 'atom') {
     $template->param($format => 1);
     $template->param(timestamp => strftime("%Y-%m-%dT%H:%M:%S-00:00", gmtime)) if ($format eq 'atom'); 
     # FIXME - the timestamp is a hack - the biblio update timestamp should be used for each
@@ -329,7 +332,7 @@ if ( $template_type && $template_type eq 'advsearch' ) {
     # shouldn't appear on the first one, scan indexes should, adding a new
     # box should only appear on the last, etc.
     my @search_boxes_array;
-    my $search_boxes_count = 3; # begin whith 3 boxes
+    my $search_boxes_count = 3; # begin with 3 boxes
     $template->param( search_boxes_count => $search_boxes_count );
 
     if ($cgi->cookie("num_paragraph")){
@@ -457,7 +460,10 @@ my @indexes = $cgi->multi_param('idx');
 
 # if a simple index (only one)  display the index used in the top search box
 if ($indexes[0] && !$indexes[1]) {
-    $template->param("ms_".$indexes[0] => 1);
+    my $idx = "ms_".$indexes[0];
+    $idx =~ s/\,/comma/g;  # template toolkit doesn't like variables with a , in it
+    $idx =~ s/-/dash/g;  # template toolkit doesn't like variables with a dash in it
+    $template->param($idx => 1);
 }
 # an operand can be a single term, a phrase, or a complete ccl query
 my @operands = $cgi->multi_param('q');
@@ -529,7 +535,6 @@ $offset = 0 if $offset < 0;
 my $page = $cgi->param('page') || 1;
 $offset = ($page-1)*$results_per_page if $page>1;
 my $hits;
-my $expanded_facet = $params->{'expand'};
 
 # Define some global variables
 my ($error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type);
@@ -549,19 +554,22 @@ if (C4::Context->preference('OpacSuppression')) {
     }
 }
 
-my $build_params = {
-    expanded_facet => $expanded_facet,
-    suppress => $suppress
-};
-
-unless ( $cgi->param('advsearch') ) {
-    $build_params->{weighted_fields} = 1;
-}
-
 ## I. BUILD THE QUERY
 ( $error,$query,$simple_query,$query_cgi,$query_desc,$limit,$limit_cgi,$limit_desc,$query_type)
-  = $builder->build_query_compat( \@operators, \@operands,
-    \@indexes, \@limits, \@sort_by, 0, $lang, $build_params);
+  = $builder->build_query_compat(
+    \@operators,
+    \@operands,
+    \@indexes,
+    \@limits,
+    \@sort_by,
+    0,
+    $lang,
+    {
+        suppress => $suppress,
+        is_opac => 1,
+        weighted_fields => !$cgi->param('advsearch')
+    }
+);
 
 sub _input_cgi_parse {
     my @elements;
@@ -581,6 +589,18 @@ $template->param ( QUERY_INPUTS => \@query_inputs );
 ## parse the limit_cgi string and put it into a form suitable for <input>s
 my @limit_inputs = $limit_cgi ? _input_cgi_parse($limit_cgi) : ();
 
+# OpenURL
+my @OpenURL_itypes;
+if (C4::Context->preference('OPACShowOpenURL')) {
+    @OpenURL_itypes = split( /\s/, C4::Context->preference('OPACOpenURLItemTypes') );
+    $template->param(
+        OPACShowOpenURL => 1,
+        OpenURLResolverURL => C4::Context->preference('OpenURLResolverURL'),
+        OpenURLText => C4::Context->preference('OpenURLText'),
+        OpenURLImageLocation => C4::Context->preference('OpenURLImageLocation')
+    );
+}
+
 $template->param ( LIMIT_INPUTS => \@limit_inputs );
 $template->param ( OPACResultsSidebar => C4::Context->preference('OPACResultsSidebar'));
 
@@ -592,7 +612,7 @@ my $results_hashref;
 my @coins;
 
 if ($tag) {
-    $query_cgi = "tag=" .$tag . "&" . $query_cgi;
+    $query_cgi = "tag=" .  uri_escape_utf8( $tag ) . "&" . $query_cgi;
     my $taglist = get_tags({term=>$tag, approved=>1});
     $results_hashref->{biblioserver}->{hits} = scalar (@$taglist);
     my @marclist = map { C4::Biblio::GetXmlBiblio( $_->{biblionumber} ) } @$taglist;
@@ -604,7 +624,7 @@ if ($tag) {
     # FIXME: No facets for tags search.
 } elsif ($build_grouped_results) {
     eval {
-        ($error, $results_hashref, $facets) = C4::Search::pazGetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,undef,$query_type,$scan);
+        ($error, $results_hashref, $facets) = C4::Search::pazGetRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,undef,$query_type,$scan);
     };
 } else {
     $pasarParams .= '&amp;query=' . uri_escape_utf8($query);
@@ -613,7 +633,7 @@ if ($tag) {
     $pasarParams .= '&amp;query_type=' . uri_escape_utf8($query_type) if ($query_type);
     my $itemtypes_nocategory = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
     eval {
-        ($error, $results_hashref, $facets) = $searcher->search_compat($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,undef,$itemtypes_nocategory,$query_type,$scan,1);
+        ($error, $results_hashref, $facets) = $searcher->search_compat($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,undef,$itemtypes_nocategory,$query_type,$scan,1);
 };
 }
 
@@ -670,8 +690,8 @@ for (my $i=0;$i<@servers;$i++) {
             }
 
             if (C4::Context->preference('COinSinOPACResults')) {
-                my $record = GetMarcBiblio({ biblionumber => $res->{'biblionumber'} });
-                $res->{coins} = GetCOinSBiblio($record);
+                my $biblio = Koha::Biblios->find( $res->{'biblionumber'} );
+                $res->{coins} = $biblio->get_coins;
             }
             if ( C4::Context->preference( "Babeltheque" ) and $res->{normalized_isbn} ) {
                 if( my $isbn = Business::ISBN->new( $res->{normalized_isbn} ) ) {
@@ -756,7 +776,7 @@ for (my $i=0;$i<@servers;$i++) {
         }
 
         ## If there's just one result, redirect to the detail page
-        if ($total == 1 && $format ne 'rss2'
+        if ($total == 1 && $format ne 'rss'
         && $format ne 'opensearchdescription' && $format ne 'atom') {
             my $biblionumber=$newresults[0]->{biblionumber};
             if (C4::Context->preference('BiblioDefaultView') eq 'isbd') {
@@ -1010,11 +1030,7 @@ $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBook
 $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
 
 if ($offset == 0) {
-    if (IsOverDriveEnabled()) {
-        $template->param(OverDriveEnabled => 1);
-        $template->param(OverDriveLibraryID => C4::Context->preference('OverDriveLibraryID'));
-    }
-    $template->param(RecordedBooksEnabled => C4::Context->preference( 'RecordedBooksClientSecret' ) && C4::Context->preference( 'RecordedBooksLibraryID' ));
+    $template->param(firstPage => 1);
 }
 
     $template->param( borrowernumber    => $borrowernumber);