Bug 24236: Fix pagination to use query_cgi

This is still wrong, we should use page-numbers.inc, but that is a larger refactoring
This patch fixes non-QueryParser searches by simple getting an using the escaped query (query_cgi)

For QueryParser, we do what the QP code does, just uri escape the query - the way that SimpleSearch does the query parsing instead of the usual buildQuery suggest to me that we should probably switch all of this to use the general Zebra search.

The issues with reservoir should be their own bug

To test:
1 - Search for cat in cataloging search
2 - Get results and see you can paginate
3 - Search for "cat"
4 - Get results but subsequent pages empty
5 - Apply patch
6 - Repeat search for "cat"
7 - You can paginate
8 - Enable UseQueryParser syspref (don't worry about installing)
9 - Confirm can still search with quotes and paginate

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: George Williams <george@nekls.org>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Nick Clemens 2019-12-13 16:08:16 +00:00 committed by Martin Renvoize
parent 451bc0fca5
commit 367df45840
Signed by: martin.renvoize
GPG key ID: 422B469130441A0F

View file

@ -27,6 +27,7 @@
use Modern::Perl;
use CGI qw ( -utf8 );
use URI::Escape;
use C4::Auth;
use C4::Biblio;
use C4::Breeding;
@ -70,14 +71,16 @@ if ($query) {
my $QParser;
$QParser = C4::Context->queryparser if (C4::Context->preference('UseQueryParser'));
my $builtquery;
my $query_cgi;
my $builder = Koha::SearchEngine::QueryBuilder->new(
{ index => $Koha::SearchEngine::BIBLIOS_INDEX } );
my $searcher = Koha::SearchEngine::Search->new(
{ index => $Koha::SearchEngine::BIBLIOS_INDEX } );
if ($QParser) {
$builtquery = $query;
$query_cgi = "q=".uri_escape_utf8($query);
} else {
( undef, $builtquery, undef, undef, undef, undef, undef, undef, undef, undef ) =
( undef, $builtquery, undef, $query_cgi, undef, undef, undef, undef, undef, undef ) =
$builder->build_query_compat( undef, \@operands, undef, undef, undef, 0, $lang );
}
# find results
@ -101,7 +104,7 @@ if ($query) {
total => $total_hits,
query => $query,
resultsloop => \@newresults,
pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?q=$query&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
pagination_bar => pagination_bar( "/cgi-bin/koha/cataloguing/addbooks.pl?$query_cgi&", getnbpages( $total_hits, $results_per_page ), $page, 'page' ),
);
}