Bug 24236: Fix pagination to use query_cgi
authorNick Clemens <nick@bywatersolutions.com>
Fri, 13 Dec 2019 16:08:16 +0000 (16:08 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 23 Jan 2020 09:01:36 +0000 (09:01 +0000)
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>

cataloguing/addbooks.pl

index 2082913..b9ed6ff 100755 (executable)
@@ -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' ),
     );
 }