Bugzilla – Attachment 57870 Details for
Bug 14715
Results per page setting for catalog search in staff client and OPAC
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14715: results per page setting for catalog search
Bug-14715-results-per-page-setting-for-catalog-sea.patch (text/plain), 13.25 KB, created by
Aleisha Amohia
on 2016-12-02 00:19:15 UTC
(
hide
)
Description:
Bug 14715: results per page setting for catalog search
Filename:
MIME Type:
Creator:
Aleisha Amohia
Created:
2016-12-02 00:19:15 UTC
Size:
13.25 KB
patch
obsolete
>From fde95c04f7f093435d97c0a8842553bf40b62fad Mon Sep 17 00:00:00 2001 >From: Martin Stenberg <martin@xinxidi.net> >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 >--- > 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 | 15 ++++++++++++++ > opac/opac-search.pl | 16 ++++++++++----- > 6 files changed, 61 insertions(+), 16 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_14715-searchresults_syspref.sql > >diff --git a/C4/Search.pm b/C4/Search.pm >index b1b9b0e..7b2fa4b 100644 >--- a/C4/Search.pm >+++ b/C4/Search.pm >@@ -443,7 +443,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 { >@@ -1884,7 +1884,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 e4e5e66..e2ecbf5 100755 >--- a/catalogue/search.pl >+++ b/catalogue/search.pl >@@ -150,7 +150,7 @@ use C4::Members qw(GetMember); > use URI::Escape; > use POSIX qw(ceil floor); > use C4::Search::History; >- >+use String::Random; > use Koha::LibraryCategories; > use Koha::Virtualshelves; > use Koha::SearchEngine::Search; >@@ -446,10 +446,16 @@ 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 $offset = $params->{'offset'} || 0; >+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 = ($page-1)*$results_per_page; >+my $offset = $params->{'offset'} || 0; > my $hits; > my $expanded_facet = $params->{'expand'}; > >@@ -536,6 +542,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"}); >@@ -599,7 +606,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 0000000..4cc263a >--- /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 031c1f8..fb4da7a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt >@@ -95,9 +95,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 = "<label for=\"addto\">"+_("Add to:")+"<\/label><select name=\"addto\" id=\"addto\"><option value=\"\"><\/option>"; > [% IF ( intranetbookbag ) %] param1 += "<option value=\"addtocart\">"+_("Cart")+"<\/option>"; [% END %] >@@ -342,7 +346,7 @@ var holdForPatron = function () { > > [% IF ( total ) %] > <div id="searchheader"> >- <form action="/cgi-bin/koha/catalogue/search.pl" method="get" id="sortbyform"> >+ <form action="/cgi-bin/koha/catalogue/search.pl" method="get" id="resultoptionsform"> > [% IF ( searchdesc ) %] > [% FOREACH QUERY_INPUT IN QUERY_INPUTS %] > <input type="hidden" name="[% QUERY_INPUT.input_name |html %]" value="[% QUERY_INPUT.input_value |html %]"/> >@@ -356,8 +360,19 @@ var holdForPatron = function () { > <select id="sort_by" name="sort_by"> > [% INCLUDE 'resort_form.inc' %] > </select> >- <input type="submit" value="Go" /> > <!-- RESORT END --> >+ <!-- RESULTS_PER_PAGE START --> >+ <label for="results_per_page">Results per page: </label> >+ <select id="results_per_page" name="results_per_page"> >+ <option value="20" [% 'SELECTED' IF results_per_page == '20' %]>20</option> >+ <option value="40" [% 'SELECTED' IF results_per_page == '40' %]>40</option> >+ <option value="60" [% 'SELECTED' IF results_per_page == '60' %]>60</option> >+ <option value="80" [% 'SELECTED' IF results_per_page == '80' %]>80</option> >+ <option value="100" [% 'SELECTED' IF results_per_page == '100' %]>100</option> >+ <option value="all" [% 'SELECTED' IF results_per_page == 'all' %]>all</option> >+ </select> >+ <!-- RESULTS_PER_PAGE END --> >+ <input type="submit" value="Go" /> > </form> > <h3> > [% total %] result(s) found [% IF ( query_desc ) %]for <span style="font-weight: bold;">'[% query_desc |html %]'</span>[% END %][% IF limit_desc %] with limit(s): <span style="font-weight: bold;">'[% limit_desc | html %]'</span>[% END %][% IF ( LibraryName ) %] in [% LibraryName %] Catalog[% END %].<br /> >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 2d85671..a5ecf14 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-results.tt >@@ -145,6 +145,17 @@ > [% UNLESS tag %] > <div class="sort_by pull-right"> > <select id="sort_by" class="resort" name="sort_by"> [% INCLUDE 'resort_form.inc' %] </select> >+ >+ <label for="results_per_page">Results per page: </label> >+ <select id="results_per_page" name="results_per_page"> >+ <option value="20" [% 'SELECTED' IF results_per_page == '20' %]>20</option> >+ <option value="40" [% 'SELECTED' IF results_per_page == '40' %]>40</option> >+ <option value="60" [% 'SELECTED' IF results_per_page == '60' %]>60</option> >+ <option value="80" [% 'SELECTED' IF results_per_page == '80' %]>80</option> >+ <option value="100" [% 'SELECTED' IF results_per_page == '100' %]>100</option> >+ <option value="all" [% 'SELECTED' IF results_per_page == 'all' %]>all</option> >+ </select> >+ > <input type="submit" class="btn btn-small clearfix" id="sortsubmit" value="Go" /> > </div> > [% END %] >@@ -792,6 +803,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("<a id=\"CheckNone\" href=\"#\">"+_("Clear all")+"<\/a>"); > $("span.checkall").html("<a id=\"CheckAll\" href=\"#\">"+_("Select all")+"<\/a>"); > >diff --git a/opac/opac-search.pl b/opac/opac-search.pl >index 3c07b88..02e5e0b 100755 >--- a/opac/opac-search.pl >+++ b/opac/opac-search.pl >@@ -518,10 +518,9 @@ 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 $offset = $params->{'offset'} || 0; >+my $results_per_page = $params->{'results_per_page'} || $cgi->cookie("results_per_page") || $count; > my $page = $cgi->param('page') || 1; >-$offset = ($page-1)*$results_per_page if $page>1; >+my $offset = $params->{'offset'} || 0; > my $hits; > my $expanded_facet = $params->{'expand'}; > >@@ -603,7 +602,13 @@ 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); >+ unless($results_per_page =~ /\d+/) { # all >+ # pazpar2 expects $results_per_page to be an integer, we hack around >+ # this by setting $results_per_page to the max value of a 32bit >+ # signed int - as defined by parpaz2 session.c:perform_termlist() >+ $results_per_page = 2147483647; >+ } >+ ($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); >@@ -629,6 +634,7 @@ 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"}; >+ $results_per_page = $hits if $results_per_page == 'all'; > my $page = $cgi->param('page') || 0; > my @newresults; > if ($build_grouped_results) { >@@ -785,7 +791,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); > my $hide = C4::Context->preference('OpacHiddenItems'); > $hide = ($hide =~ m/\S/) if $hide; # Just in case it has some spaces/new lines > my $branch = ''; >-- >2.1.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14715
:
41949
|
42003
|
42742
|
42743
|
56002
|
56003
|
56004
|
56005
|
56575
|
56576
|
56577
|
56610
|
56611
|
56612
|
57870
|
61721
|
64250
|
67912
|
67913
|
68000
|
68001
|
68305
|
68327
|
75938
|
75939
|
75940
|
75941
|
78230
|
78298
|
78299
|
78300
|
78301
|
78302
|
79796
|
79797
|
79988
|
81203
|
88097
|
88102
|
88103
|
88104
|
88105
|
88106
|
88107
|
88108
|
88109
|
88126
|
88195
|
88831
|
88832
|
88833
|
88834
|
88835
|
88836
|
88837
|
88838
|
88839
|
95038
|
97004
|
98365
|
99607
|
99677
|
99684
|
99685
|
101775
|
101776
|
101777
|
101778