Bug 19502: Limit pagination to first 10000 results when using ES
authorNick Clemens <nick@bywatersolutions.com>
Fri, 16 Mar 2018 11:10:37 +0000 (11:10 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Thu, 12 Jul 2018 13:04:20 +0000 (13:04 +0000)
This patch is to avoid hitting an error page. We should eventually make the
max number returned configurable for ES.

To test:
1 - Have Koha running ES with 10,000+ records
2 - Search for '*'
3 - Click 'Last' to view last page of results
4 - 'Cannot perform search' error
5 - Apply patch
6 - Search again
7 - View 'Last' page
8 - No error, you go to the last of 10000
9 - Note the warning above the pagination buttons

Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Alex Arnaud <alex.arnaud@biblibre.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

catalogue/search.pl
koha-tmpl/intranet-tmpl/prog/en/includes/page-numbers.inc
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/results.tt
koha-tmpl/opac-tmpl/bootstrap/en/includes/page-numbers.inc
koha-tmpl/opac-tmpl/bootstrap/en/includes/search/page-numbers.inc
opac/opac-search.pl

index 6fc96d6..7e2e300 100755 (executable)
@@ -619,8 +619,9 @@ for (my $i=0;$i<@servers;$i++) {
             ## FIXME: add a global function for this, it's better than the current global one
             ## Build the page numbers on the bottom of the page
             my @page_numbers;
+            my $hits_to_paginate = C4::Context->preference('SearchEngine') eq 'Elasticsearch' ? 10000 : $hits;
             # total number of pages there will be
-            my $pages = ceil($hits / $results_per_page);
+            my $pages = ceil($hits_to_paginate / $results_per_page);
             my $last_page_offset = ( $pages -1 ) * $results_per_page;
             # default page number
             my $current_page_number = 1;
index af4bc09..387d09f 100644 (file)
@@ -1,4 +1,5 @@
 [% IF ( PAGE_NUMBERS ) %]<nav><ul class="pagination">
+ [% IF Koha.Preference('SearchEngine') == 'Elasticsearch' %]<h6>10,000 results loaded, refine your search to view other records</h6>[% END %]
     [% IF ( previous_page_offset.defined ) %]
         <li><a class="nav" href="/cgi-bin/koha/catalogue/search.pl?[% query_cgi |html %][% limit_cgi |html %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |url %][% END %]">First</a></li>
         <!-- Row of numbers corresponding to search result pages -->
index c2fb64c..0b7c63d 100644 (file)
         [% ELSE %]
 
             <div id="searchresults">
-
                 [% INCLUDE 'page-numbers.inc' %]
 
                 <form action="/cgi-bin/koha/catalogue/search.pl" method="get" name="bookbag_form" id="bookbag_form">
index fbfdfc8..484fa5c 100644 (file)
@@ -1,5 +1,6 @@
 [% IF ( PAGE_NUMBERS ) %]
     <div class="pagination pagination-small noprint">
+     [% IF Koha.Preference('SearchEngine') == 'Elasticsearch' %]<h6>10000 results loaded, refine your search to view other records</h6>[% END %]
         <ul>
             [% IF ( previous_page_offset.defined ) %]
                 <li><a href="/cgi-bin/koha/opac-search.pl?[% query_cgi |html %][% limit_cgi |html %][% IF ( sort_by ) %]&amp;sort_by=[% sort_by |html %][% END %]">First</a></li>
index 2de511f..807417b 100644 (file)
@@ -1,5 +1,6 @@
 [% IF ( PAGE_NUMBERS ) %]
   <div class="pages">
+   [% IF Koha.Preference('SearchEngine') == 'Elasticsearch' %]<h6>10000 results loaded, refine your search to view other records</h6>[% END %]
     [% IF ( previous_page ) %]
       <a class="nav" href="?[% FOREACH fp IN follower_params %][% fp.var |url %]=[% fp.val |url %]&amp;[% END %]page=[% previous_page |url %]">&lt;&lt; Previous</a>
     [% END %]
index 1d7615b..9cfb3fa 100755 (executable)
@@ -830,8 +830,9 @@ for (my $i=0;$i<@servers;$i++) {
            }
             ## Build the page numbers on the bottom of the page
             my @page_numbers;
+            my $hits_to_paginate = C4::Context->preference('SearchEngine') eq 'Elasticsearch' ? 10000 : $hits;
             # total number of pages there will be
-            my $pages = ceil($hits / $results_per_page);
+            my $pages = ceil($hits_to_paginate / $results_per_page);
             my $last_page_offset = ( $pages - 1 ) * $results_per_page;
             # default page number
             my $current_page_number = 1;