From e7389052231dfeb48a040bf368669627ca18b699 Mon Sep 17 00:00:00 2001 From: Maneesh P M Date: Thu, 22 Apr 2021 12:38:58 +0530 Subject: [PATCH] Fix pagination by setting pageLength properly The pageLength parameter of kiwix::SearchRenderer is not set properly which causes it to take an arbitrary large value breaking pagination. The solution is to use the same convention as kiwix-serve. Try to read the pageLength from query if found, else use a default value of 25. Use this pageLength to find end. Use renderer.setPageLength() method to set the pageLength properly. --- src/urlschemehandler.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/urlschemehandler.cpp b/src/urlschemehandler.cpp index 245ea8d..f54f9d0 100644 --- a/src/urlschemehandler.cpp +++ b/src/urlschemehandler.cpp @@ -101,10 +101,12 @@ UrlSchemeHandler::handleSearchRequest(QWebEngineUrlRequestJob* request) int temp = query.queryItemValue("start").toInt(&ok); if (ok) start = temp; - int end = 25; - temp = query.queryItemValue("end").toInt(&ok); + int pageLength = 25; + temp = query.queryItemValue("pageLength").toInt(&ok); if (ok) - end = temp; + pageLength = temp; + + auto end = start + pageLength; auto searcher = app->getLibrary()->getSearcher(bookId); searcher->search(searchQuery, start, end); @@ -115,6 +117,7 @@ UrlSchemeHandler::handleSearchRequest(QWebEngineUrlRequestJob* request) renderer.setSearchContent(bookId.toStdString()); renderer.setProtocolPrefix("zim://"); renderer.setSearchProtocolPrefix("zim://" + host.toStdString() + "/?"); + renderer.setPageLength(pageLength); auto content = renderer.getHtml(); QBuffer *buffer = new QBuffer; buffer->setData(content.data(), content.size());