mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-28 05:49:35 +00:00
Build the bookSelection query string when we parse the query.
We have to reuse the query the user give us to generate the pagination links. At search result rendering step we don't have access to the query object. The best place to know which arguments are used to select books (and so which arguments to keep in the pagination links) is when we parse the query to select books. Fix tests (pagination links) with book selector other than "books.id=" (pattern=jazz&books.query.lang=eng)
This commit is contained in:
@ -71,9 +71,9 @@ void SearchRenderer::setSearchPattern(const std::string& pattern)
|
||||
searchPattern = pattern;
|
||||
}
|
||||
|
||||
void SearchRenderer::setSearchBookIds(const std::set<std::string>& bookIds)
|
||||
void SearchRenderer::setSearchBookQuery(const std::string& bookQuery)
|
||||
{
|
||||
searchBookIds = bookIds;
|
||||
searchBookQuery = bookQuery;
|
||||
}
|
||||
|
||||
void SearchRenderer::setProtocolPrefix(const std::string& prefix)
|
||||
@ -90,15 +90,13 @@ kainjow::mustache::data buildQueryData
|
||||
(
|
||||
const std::string& searchProtocolPrefix,
|
||||
const std::string& pattern,
|
||||
const std::set<std::string>& bookIds
|
||||
const std::string& bookQuery
|
||||
) {
|
||||
kainjow::mustache::data query;
|
||||
query.set("pattern", kiwix::encodeDiples(pattern));
|
||||
std::ostringstream ss;
|
||||
ss << searchProtocolPrefix << "?pattern=" << urlEncode(pattern, true);
|
||||
for (auto& bookId: bookIds) {
|
||||
ss << "&books.id="<<urlEncode(bookId, true);
|
||||
}
|
||||
ss << "&" << bookQuery;
|
||||
query.set("unpaginatedQuery", ss.str());
|
||||
return query;
|
||||
}
|
||||
@ -199,7 +197,7 @@ std::string SearchRenderer::getHtml()
|
||||
kainjow::mustache::data query = buildQueryData(
|
||||
searchProtocolPrefix,
|
||||
searchPattern,
|
||||
searchBookIds
|
||||
searchBookQuery
|
||||
);
|
||||
|
||||
std::string template_str = RESOURCE::templates::search_result_html;
|
||||
|
Reference in New Issue
Block a user