From cf7da7b09e9064eaddeb31caa50d2c9575bb5acf Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 4 Oct 2018 13:09:56 +0000 Subject: [PATCH] Bug 21405: Fix authorities pagination for Zebra and ES This patch corrects a problem introduced by bug 20261 The underlying problem still exists - the two search_auth_compat methods don't expect the same information. Using the 'options' parameter allows us to work around this for ES. Additionally code is added to avoid asking for more results form ES than are returned. To test: 1 - Perform an authorities search with 1+ pages using Zebra 2 - Page through results, note you are only offseeting by 1 each time 3 - Perform an authorities search with 10,000+ results in ES 4 - Click on the last page and get an error 5 - Apply patch 6 - Retry Zebra search 7 - Results should paginate correctly 8 - Clicking on last page should return last results 9 - Retry ES results 10 - Results should paginate correctly 11 - Clicking on last page hsould return last results --- Koha/SearchEngine/Elasticsearch/Search.pm | 4 +++- authorities/authorities-home.pl | 17 +++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch/Search.pm b/Koha/SearchEngine/Elasticsearch/Search.pm index 6340ebe..8bc147b 100644 --- a/Koha/SearchEngine/Elasticsearch/Search.pm +++ b/Koha/SearchEngine/Elasticsearch/Search.pm @@ -187,7 +187,9 @@ results in a form the same as L. sub search_auth_compat { my $self = shift; - # TODO handle paging + # FIXME the options here should match zebra - we take page, but should take offset + # page is calculated to offset in search above, though we can pass offset directly too + # via options my $database = Koha::Database->new(); my $schema = $database->schema(); my $res = $self->search(@_); diff --git a/authorities/authorities-home.pl b/authorities/authorities-home.pl index 3f40072..a65eb5b 100755 --- a/authorities/authorities-home.pl +++ b/authorities/authorities-home.pl @@ -23,6 +23,7 @@ use warnings; use CGI qw ( -utf8 ); use URI::Escape; use C4::Auth; +use POSIX qw(ceil); use C4::Context; use C4::Auth; @@ -95,8 +96,9 @@ if ( $op eq "do_search" ) { [$marclist], [$and_or], [$excluding], [$operator], [$value], $authtypecode, $orderby ); + my $offset = ( $startfrom - 1 ) * $resultsperpage + 1; my ( $results, $total ) = $searcher->search_auth_compat( - $search_query, $startfrom, $resultsperpage + $search_query, $offset, $resultsperpage, ( offset => $offset - 1 ) ); ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -180,15 +182,18 @@ if ( $op eq "do_search" ) { $template->param( result => $results ) if $results; + my $max_result_window = $searcher->max_result_window; + my $hits_to_paginate = ($max_result_window && $max_result_window < $total) ? $max_result_window : $total; $template->param( pagination_bar => pagination_bar( - $base_url, int( $total / $resultsperpage ) + 1, + $base_url, ceil( $hits_to_paginate / $resultsperpage ) , $startfrom, 'startfrom' ), - total => $total, - from => $from, - to => $to, - isEDITORS => $authtypecode eq 'EDITORS', + total => $total, + hits_to_paginate => $hits_to_paginate, + from => $from, + to => $to, + isEDITORS => $authtypecode eq 'EDITORS', ); } -- 2.1.4