X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=opac%2Fopac-search.pl;h=9b78069df8fcfaeb3625711d90791c64217a6677;hb=eba64bf25d8da0f091ce0b5d8329385638fb1fe1;hp=a142cb1f93502ff346afb149b0e4d89707f3b3ea;hpb=b1ed3af63350d0d754fb309644b3d57be707041b;p=koha.git diff --git a/opac/opac-search.pl b/opac/opac-search.pl index a142cb1f93..9b78069df8 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -1,6 +1,7 @@ #!/usr/bin/perl # Copyright 2008 Garry Collum and the Koha Koha Development team +# Copyright 2010 BibLibre # # This file is part of Koha. # @@ -65,7 +66,7 @@ my $build_grouped_results = C4::Context->preference('OPACGroupResults'); if ($format =~ /(rss|atom|opensearchdescription)/) { $template_name = 'opac-opensearch.tmpl'; } -elsif ($build_grouped_results) { +elsif (@params && $build_grouped_results) { $template_name = 'opac-results-grouped.tmpl'; } elsif ((@params>=1) || ($cgi->param("q")) || ($cgi->param('multibranchlimit')) || ($cgi->param('limit-yr')) ) { @@ -80,9 +81,12 @@ else { template_name => $template_name, query => $cgi, type => "opac", - authnotrequired => 1, + authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ), } ); +if ($template_name eq 'opac-results.tmpl') { + $template->param('COinSinOPACResults' => C4::Context->preference('COinSinOPACResults')); +} if ($format eq 'rss2' or $format eq 'opensearchdescription' or $format eq 'atom') { $template->param($format => 1); @@ -97,6 +101,7 @@ elsif (C4::Context->preference("marcflavour") eq "MARC21" ) { $template->param('usmarc' => 1); } $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') ); +$template->param( 'OPACNoResultsFound' => C4::Context->preference('OPACNoResultsFound') ); if (C4::Context->preference('BakerTaylorEnabled')) { $template->param( @@ -138,10 +143,9 @@ if (C4::Context->preference('TagsEnabled')) { #} # load the branches -my $mybranch = ( C4::Context->preference('SearchMyLibraryFirst') && C4::Context->userenv && C4::Context->userenv->{branch} ) ? C4::Context->userenv->{branch} : ''; + my $branches = GetBranches(); # used later in *getRecords, probably should be internalized by those functions after caching in C4::Branch is established $template->param( - branchloop => GetBranchesLoop($mybranch, 0), searchdomainloop => GetBranchCategories(undef,'searchdomain'), ); @@ -160,8 +164,8 @@ my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes"); if (!$advanced_search_types or $advanced_search_types eq 'itemtypes') { foreach my $thisitemtype ( sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) { - my %row =( number=>$cnt++, - ccl => $itype_or_itemtype, + my %row =( number=>$cnt++, + ccl => "$itype_or_itemtype,phr", code => $thisitemtype, selected => $selected, description => $itemtypes->{$thisitemtype}->{'description'}, @@ -316,7 +320,7 @@ my @limits; @limits = split("\0",$params->{'limit'}) if $params->{'limit'}; if($params->{'multibranchlimit'}) { -push @limits, join(" or ", map { "branch: $_ "} @{GetBranchesInCategory($params->{'multibranchlimit'})}) ; + push @limits, '('.join( " or ", map { "branch: $_ " } @{ GetBranchesInCategory( $params->{'multibranchlimit'} ) } ).')'; } my $available; @@ -344,6 +348,7 @@ if ($params->{'limit-yr'}) { # Params that can only have one value my $scan = $params->{'scan'}; my $count = C4::Context->preference('OPACnumSearchResults') || 20; +my $countRSS = C4::Context->preference('numSearchRSSResults') || 50; my $results_per_page = $params->{'count'} || $count; my $offset = $params->{'offset'} || 0; my $page = $cgi->param('page') || 1; @@ -421,6 +426,14 @@ elsif (C4::Context->preference('NoZebra')) { ($error, $results_hashref, $facets) = getRecords($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$query_type,$scan); }; } +# This sorts the facets into alphabetical order +if ($facets) { + foreach my $f (@$facets) { + $f->{facets} = [ sort { uc($a->{facet_title_value}) cmp uc($b->{facet_title_value}) } @{ $f->{facets} } ]; + } + @$facets = sort {$a->{expand} cmp $b->{expand}} @$facets; +} + # use Data::Dumper; print STDERR "-" x 25, "\n", Dumper($results_hashref); if ($@ || $error) { $template->param(query_error => $error.$@); @@ -431,7 +444,7 @@ if ($@ || $error) { # At this point, each server has given us a result set # now we build that set for template display my @sup_results_array; -for (my $i=0;$i<=@servers;$i++) { +for (my $i=0;$i<@servers;$i++) { my $server = $servers[$i]; if ($server && $server =~/biblioserver/) { # this is the local bibliographic server $hits = $results_hashref->{$server}->{"hits"}; @@ -460,9 +473,11 @@ for (my $i=0;$i<=@servers;$i++) { limit=>$tag_quantity }); } } - foreach (@newresults) { - $_->{coins} = GetCOinSBiblio($_->{'biblionumber'}); - } + if (C4::Context->preference('COinSinOPACResults')) { + foreach (@newresults) { + $_->{coins} = GetCOinSBiblio($_->{'biblionumber'}); + } + } if ($results_hashref->{$server}->{"hits"}){ $total = $total + $results_hashref->{$server}->{"hits"}; @@ -482,10 +497,10 @@ for (my $i=0;$i<=@servers;$i++) { } # Adding the new search if needed - if ($borrowernumber eq '') { + if (!$borrowernumber || $borrowernumber eq '') { # To a cookie (the user is not logged in) - if ($params->{'offset'} eq '') { + if (($params->{'offset'}||'') eq '') { push @recentSearches, { "query_desc" => $query_desc || "unknown", @@ -496,6 +511,7 @@ for (my $i=0;$i<=@servers;$i++) { $template->param(ShowOpacRecentSearchLink => 1); } + shift @recentSearches if (@recentSearches > 15); # Pushing the cookie back $newsearchcookie = $cgi->cookie( -name => 'KohaOpacRecentSearches', @@ -507,7 +523,7 @@ for (my $i=0;$i<=@servers;$i++) { } else { # To the session (the user is logged in) - if ($params->{'offset'} eq '') { + if (($params->{'offset'}||'') eq '') { AddSearchHistory($borrowernumber, $cgi->cookie("CGISESSID"), $query_desc, $query_cgi, $total); $template->param(ShowOpacRecentSearchLink => 1); } @@ -532,9 +548,11 @@ for (my $i=0;$i<=@servers;$i++) { $limit_cgi_not_availablity =~ s/&limit=available//g if defined $limit_cgi_not_availablity; $template->param(limit_cgi_not_availablity => $limit_cgi_not_availablity); $template->param(limit_cgi => $limit_cgi); + $template->param(countrss => $countRSS ); $template->param(query_cgi => $query_cgi); $template->param(query_desc => $query_desc); $template->param(limit_desc => $limit_desc); + $template->param(offset => $offset); $template->param(DisplayMultiPlaceHold => $DisplayMultiPlaceHold); if ($query_desc || $limit_desc) { $template->param(searchdesc => 1); @@ -600,7 +618,6 @@ for (my $i=0;$i<=@servers;$i++) { for my $sup_record ( @{$results_hashref->{$server}->{"RECORDS"}} ) { my $marc_record_object = MARC::Record->new_from_usmarc($sup_record); my $title_field = $marc_record_object->field(100); - warn "Authority Found: ".$marc_record_object->as_formatted(); push @inner_sup_results_array, { 'title' => $title_field->subfield('a'), 'link' => "&idx=an&q=".$marc_record_object->field('001')->as_string(), @@ -620,6 +637,7 @@ $template->param( total => $total, opacfacets => 1, facets_loop => $facets, + displayFacetCount=> C4::Context->preference('displayFacetCount')||0, scan => $scan, search_error => $error, );