From f98f6a1b6734142c0efec292132f4b3676f25381 Mon Sep 17 00:00:00 2001 From: Martin Stenberg Date: Tue, 25 Aug 2015 20:21:25 +0200 Subject: [PATCH] Bug 14715: results per page setting for catalog search Add new select field to catalog search results pages which allows user to set number of results to be shown per page. Setting saved in cookie "results_per_page". To test: 1) Do a catalog search in the intranet and OPAC 2) Confirm that results automatically update upon selection of results per page to show 3) Test for all options (20, 40, 60, 80, 100, all) Bug 14715: syspref for results per page options Remove the "all" option. Add syspref [OPAC]numSearchResultsPerPage for specifying options for numbers of results per page including [OPAC]numSearchResults. Bug 14715: database updates Bug 14715: Fixing pagination problems Signed-off-by: Owen Leonard Signed-off-by: Cab Vinton Signed-off-by: Liz Rea --- C4/Search.pm | 4 +-- catalogue/search.pl | 20 +++++++---- .../bug_14715-searchresults_syspref.sql | 2 ++ .../prog/en/modules/catalogue/results.tt | 41 +++++++++++++++++++++- .../opac-tmpl/bootstrap/en/modules/opac-results.tt | 14 ++++++++ opac/opac-search.pl | 9 +++-- 6 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_14715-searchresults_syspref.sql diff --git a/C4/Search.pm b/C4/Search.pm index 1a9f51b4e1..5d3dbb26e5 100644 --- a/C4/Search.pm +++ b/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 { @@ -1898,7 +1898,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 { diff --git a/catalogue/search.pl b/catalogue/search.pl index 514c4a9b2c..e70dac9c51 100755 --- a/catalogue/search.pl +++ b/catalogue/search.pl @@ -148,7 +148,7 @@ use C4::Koha; use URI::Escape; use POSIX qw(ceil floor); use C4::Search::History; - +use String::Random; use Koha::ItemTypes; use Koha::Library::Groups; use Koha::Patrons; @@ -454,11 +454,18 @@ 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'}; # Define some global variables @@ -553,7 +560,8 @@ my @sup_results_array; for (my $i=0;$i<@servers;$i++) { my $server = $servers[$i]; if ($server =~/biblioserver/) { # this is the local bibliographic server - my $hits = $results_hashref->{$server}->{"hits"} // 0; + $hits = $results_hashref->{$server}->{"hits"} // 0; + $results_per_page = $hits if $results_per_page == 'all'; my $page = $cgi->param('page') || 0; my @newresults = searchResults({ 'interface' => 'intranet' }, $query_desc, $hits, $results_per_page, $offset, $scan, $results_hashref->{$server}->{"RECORDS"}); @@ -619,7 +627,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) { diff --git a/installer/data/mysql/atomicupdate/bug_14715-searchresults_syspref.sql b/installer/data/mysql/atomicupdate/bug_14715-searchresults_syspref.sql new file mode 100644 index 0000000000..4cc263a42b --- /dev/null +++ b/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'); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt index ca3733f806..7e014db1b1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt @@ -20,6 +20,7 @@ [% INCLUDE 'doc-head-open.inc' %] Koha › Catalog › [% IF ( searchdesc ) %]Results of search [% IF ( query_desc ) %]for '[% query_desc | html %]'[% END %][% IF ( limit_desc ) %] with limit(s): '[% limit_desc | html %]'[% END %][% ELSE %]You did not specify any search criteria[% END %] [% INCLUDE 'doc-head-close.inc' %] +}); @@ -61,8 +62,38 @@
-
+
+ [% IF ( searchdesc ) %] + [% FOREACH QUERY_INPUT IN QUERY_INPUTS %] + + [% END %] + [% FOREACH LIMIT_INPUT IN LIMIT_INPUTS %] + + [% END %] + [% END %] + + + + + + + + + +
+

+ [% total %] result(s) found [% IF ( query_desc ) %]for '[% query_desc |html %]'[% END %][% IF limit_desc %] with limit(s): '[% limit_desc | html %]'[% END %][% IF ( LibraryName ) %] in [% LibraryName %] Catalog[% END %].
  +

Select all | Clear all @@ -629,6 +660,14 @@ stickTo: "main", stickyClass: "floating" }); + $('#resultoptionsform').find("input:submit").hide(); + $('#sort_by').change(function() { + $('#resultoptionsform').submit(); + }); + $('#results_per_page').change(function() { + $.cookie('results_per_page', $(this).val()); + $('#resultoptionsform').submit(); + }); $("#cartsubmit").click(function(e){ e.preventDefault(); diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt index 2e233f1d1a..1db0a053bf 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt @@ -164,6 +164,16 @@ [% UNLESS tag %]
+ + + +
[% END %] @@ -828,6 +838,10 @@ $(document).ready(function(){ $('.resort').change(function() { $('#bookbag_form').submit(); }); + $('#results_per_page').change(function() { + $.cookie('results_per_page', $(this).val()); + $('#bookbag_form').submit(); + }); $("span.clearall").html(""+_("Clear all")+"<\/a>"); $("span.checkall").html(""+_("Select all")+"<\/a>"); diff --git a/opac/opac-search.pl b/opac/opac-search.pl index e0d3dd6229..0e7f8c3a7c 100755 --- a/opac/opac-search.pl +++ b/opac/opac-search.pl @@ -523,11 +523,10 @@ if ($params->{'limit-yr'}) { 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 $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; -$offset = ($page-1)*$results_per_page if $page>1; my $hits; my $expanded_facet = $params->{'expand'}; @@ -604,7 +603,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,$expanded_facet,$query_type,$scan); }; } else { $pasarParams .= '&query=' . uri_escape_utf8($query); @@ -801,7 +800,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); my $hide = C4::Context->preference('OpacHiddenItems'); $hide = ($hide =~ m/\S/) if $hide; # Just in case it has some spaces/new lines my $branch = ''; -- 2.11.0