From 64dc5131c0357a6a626b2e3da0dec89c9b82e8c8 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 27 Nov 2017 12:37:13 +0000 Subject: [PATCH 1/2] Be able to specify the global contentHumanReadableId without a index. Even if we use the add_reader method to search into embedded full text index, we need to specify the global `contentHumanReadableId` as it will be used to generate "page links". --- include/searcher.h | 2 +- src/searcher.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/searcher.h b/include/searcher.h index 3a1950cab..4f07c0796 100644 --- a/include/searcher.h +++ b/include/searcher.h @@ -56,7 +56,7 @@ struct SearcherInternal; class Searcher { public: - Searcher(); + Searcher(const string& humanReadableName = ""); Searcher(const string& xapianDirectoryPath, Reader* reader, const string& humanReadableName); diff --git a/src/searcher.cpp b/src/searcher.cpp index ca8f8e415..4010bdc87 100644 --- a/src/searcher.cpp +++ b/src/searcher.cpp @@ -85,17 +85,17 @@ Searcher::Searcher(const string& xapianDirectoryPath, resultCountPerPage(0), estimatedResultCount(0), resultStart(0), - resultEnd(0) + resultEnd(0), + contentHumanReadableId(humanReadableName) { loadICUExternalTables(); if (!reader || !reader->hasFulltextIndex()) { internal->_xapianSearcher = new XapianSearcher(xapianDirectoryPath, reader); } - this->contentHumanReadableId = humanReadableName; this->humanReaderNames.push_back(humanReadableName); } -Searcher::Searcher() +Searcher::Searcher(const std::string& humanReadableName) : internal(new SearcherInternal()), searchPattern(""), protocolPrefix("zim://"), @@ -103,7 +103,8 @@ Searcher::Searcher() resultCountPerPage(0), estimatedResultCount(0), resultStart(0), - resultEnd(0) + resultEnd(0), + contentHumanReadableId(humanReadableName) { loadICUExternalTables(); } From 41c92cfc3c2240836d3f4014081626a7e2404024 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 27 Nov 2017 12:39:04 +0000 Subject: [PATCH 2/2] Better calculate the start of the last search page. The increment between pages should always be a multiple of `resultCountPerPage`. --- src/searcher.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/searcher.cpp b/src/searcher.cpp index 4010bdc87..c7c6222f3 100644 --- a/src/searcher.cpp +++ b/src/searcher.cpp @@ -17,6 +17,9 @@ * MA 02110-1301, USA. */ + +#include + #include "searcher.h" #include "kiwixlib-resources.h" #include "reader.h" @@ -432,7 +435,7 @@ string Searcher::getHtml() oData["resultRange"] = this->resultCountPerPage; oData["resultLastPageStart"] = this->estimatedResultCount > this->resultCountPerPage - ? this->estimatedResultCount - this->resultCountPerPage + ? std::round(this->estimatedResultCount / this->resultCountPerPage) * this->resultCountPerPage : 0; oData["protocolPrefix"] = this->protocolPrefix; oData["searchProtocolPrefix"] = this->searchProtocolPrefix;