@@ -, +, @@ --- C4/Search.pm | 4 ++-- catalogue/search.pl | 17 +++++++++++----- .../bug_14715-searchresults_syspref.sql | 2 ++ .../prog/en/modules/catalogue/results.tt | 23 ++++++++++++++++++---- .../opac-tmpl/bootstrap/en/modules/opac-results.tt | 14 +++++++++++++ opac/opac-search.pl | 9 ++++----- 6 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_14715-searchresults_syspref.sql --- a/C4/Search.pm +++ a/C4/Search.pm @@ -446,7 +446,7 @@ sub getRecords { # loop through the results $results_hash->{'hits'} = $size; my $times; - if ( $offset + $results_per_page <= $size ) { + if ( $results_per_page != 'all' && ($offset + $results_per_page <= $size) ) { $times = $offset + $results_per_page; } else { @@ -1888,7 +1888,7 @@ sub searchResults { # handle which records to actually retrieve my $times; - if ( $hits && $offset + $results_per_page <= $hits ) { + if ( $hits && $results_per_page != 'all' && ($offset + $results_per_page <= $hits) ) { $times = $offset + $results_per_page; } else { --- a/catalogue/search.pl +++ a/catalogue/search.pl @@ -149,7 +149,7 @@ use C4::Koha; use URI::Escape; use POSIX qw(ceil floor); use C4::Search::History; - +use String::Random; use Koha::ItemTypes; use Koha::LibraryCategories; use Koha::Patrons; @@ -447,11 +447,17 @@ for (my $ii = 0; $ii < @operands; ++$ii) # Params that can only have one value my $scan = $params->{'scan'}; my $count = C4::Context->preference('numSearchResults') || 20; -my $results_per_page = $params->{'count'} || $count; +my @results_per_page_options = grep /^\d+$/, + map {s/\s+//g;$_;} + split /,/, C4::Context->preference('numSearchResultsPerPage'); +push(@results_per_page_options, $count); +@results_per_page_options = do { my %seen; grep { !$seen{$_}++ } @results_per_page_options }; +@results_per_page_options = sort {$a <=> $b} @results_per_page_options; + +my $results_per_page = $params->{'results_per_page'} || $cgi->cookie("results_per_page") || $count; +my $page = $cgi->param('page') || 1; my $offset = $params->{'offset'} || 0; $offset = 0 if $offset < 0; -my $page = $cgi->param('page') || 1; -#my $offset = ($page-1)*$results_per_page; my $hits; my $expanded_facet = $params->{'expand'}; @@ -538,6 +544,7 @@ for (my $i=0;$i<@servers;$i++) { my $server = $servers[$i]; if ($server =~/biblioserver/) { # this is the local bibliographic server $hits = $results_hashref->{$server}->{"hits"}; + $results_per_page = $hits if $results_per_page == 'all'; my $page = $cgi->param('page') || 0; my @newresults = searchResults('intranet', $query_desc, $hits, $results_per_page, $offset, $scan, $results_hashref->{$server}->{"RECORDS"}); @@ -601,7 +608,7 @@ for (my $i=0;$i<@servers;$i++) { if ($query_desc || $limit_desc) { $template->param(searchdesc => 1); } - $template->param(results_per_page => $results_per_page); + $template->param(results_per_page => $results_per_page == $hits ? 'all' : $results_per_page); # must define a value for size if not present in DB # in order to avoid problems generated by the default size value in TT foreach my $line (@newresults) { --- a/installer/data/mysql/atomicupdate/bug_14715-searchresults_syspref.sql +++ a/installer/data/mysql/atomicupdate/bug_14715-searchresults_syspref.sql @@ -0,0 +1,2 @@ +INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`,`type`) VALUES ('OPACnumSearchResultsPerPage', '10,20,40,60,80,100', NULL, 'Option list of number of results per page to show in OPAC search results','YesNo'); +INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`,`type`) VALUES ('numSearchResultsPerPage', '10,20,40,60,80,100', NULL, 'Option list of number of results per page to show in staff client search results','YesNo'); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -97,9 +97,13 @@ $("#forgetholdfor").click(function(){ $(".btn-group").removeClass("open"); return false; }); -$('#sortbyform').find("input:submit").hide(); +$('#resultoptionsform').find("input:submit").hide(); $('#sort_by').change(function() { - $('#sortbyform').submit(); + $('#resultoptionsform').submit(); + }); +$('#results_per_page').change(function() { + $.cookie('results_per_page', $(this).val()); + $('#resultoptionsform').submit(); }); var param1 = "