mirror of https://github.com/kiwix/libkiwix.git
Make the search_rendered handle multizim search.
This introduce a intermediate mustache object to store information about the request made by the user.
This commit is contained in:
parent
39d0a56be8
commit
077ceac5a5
|
@ -81,9 +81,9 @@ class SearchRenderer
|
|||
void setSearchPattern(const std::string& pattern);
|
||||
|
||||
/**
|
||||
* Set the search content id.
|
||||
* Set the book names used to do the search.
|
||||
*/
|
||||
void setSearchContent(const std::string& name);
|
||||
void setSearchBookIds(const std::set<std::string>& bookIds);
|
||||
|
||||
/**
|
||||
* Set protocol prefix.
|
||||
|
@ -112,7 +112,7 @@ class SearchRenderer
|
|||
zim::SearchResultSet m_srs;
|
||||
NameMapper* mp_nameMapper;
|
||||
Library* mp_library;
|
||||
std::string searchContent;
|
||||
std::set<std::string> searchBookIds;
|
||||
std::string searchPattern;
|
||||
std::string protocolPrefix;
|
||||
std::string searchProtocolPrefix;
|
||||
|
|
|
@ -71,9 +71,9 @@ void SearchRenderer::setSearchPattern(const std::string& pattern)
|
|||
searchPattern = pattern;
|
||||
}
|
||||
|
||||
void SearchRenderer::setSearchContent(const std::string& content)
|
||||
void SearchRenderer::setSearchBookIds(const std::set<std::string>& bookIds)
|
||||
{
|
||||
searchContent = content;
|
||||
searchBookIds = bookIds;
|
||||
}
|
||||
|
||||
void SearchRenderer::setProtocolPrefix(const std::string& prefix)
|
||||
|
@ -90,13 +90,15 @@ kainjow::mustache::data buildQueryData
|
|||
(
|
||||
const std::string& searchProtocolPrefix,
|
||||
const std::string& pattern,
|
||||
const std::string& searchContent
|
||||
const std::set<std::string>& bookIds
|
||||
) {
|
||||
kainjow::mustache::data query;
|
||||
query.set("pattern", kiwix::encodeDiples(pattern));
|
||||
std::ostringstream ss;
|
||||
ss << searchProtocolPrefix << "?pattern=" << urlEncode(pattern, true);
|
||||
ss << "&content=" << urlEncode(searchContent, true);
|
||||
for (auto& bookId: bookIds) {
|
||||
ss << "&books.id="<<urlEncode(bookId, true);
|
||||
}
|
||||
query.set("unpaginatedQuery", ss.str());
|
||||
return query;
|
||||
}
|
||||
|
@ -197,7 +199,7 @@ std::string SearchRenderer::getHtml()
|
|||
kainjow::mustache::data query = buildQueryData(
|
||||
searchProtocolPrefix,
|
||||
searchPattern,
|
||||
searchContent
|
||||
searchBookIds
|
||||
);
|
||||
|
||||
std::string template_str = RESOURCE::templates::search_result_html;
|
||||
|
|
|
@ -711,8 +711,7 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
|
|||
SearchRenderer renderer(search->getResults(start, pageLength), mp_nameMapper, mp_library, start,
|
||||
search->getEstimatedMatches());
|
||||
renderer.setSearchPattern(searchInfo.pattern);
|
||||
//[TODO]
|
||||
//renderer.setSearchContent(searchInfo.bookNames);
|
||||
renderer.setSearchBookIds(bookIds);
|
||||
renderer.setProtocolPrefix(m_root + "/");
|
||||
renderer.setSearchProtocolPrefix(m_root + "/search");
|
||||
renderer.setPageLength(pageLength);
|
||||
|
|
|
@ -1611,7 +1611,7 @@ TEST_F(TaskbarlessServerTest, searchResults)
|
|||
|
||||
static std::string makeUrl(const std::string pattern, int start, size_t resultsPerPage)
|
||||
{
|
||||
std::string url = "/ROOT/search?pattern=" + pattern + "&content=zimfile";
|
||||
std::string url = "/ROOT/search?pattern=" + pattern + "&books.id=6f1d19d0-633f-087b-fb55-7ac324ff9baf";
|
||||
|
||||
if ( start >= 0 ) {
|
||||
url += "&start=" + to_string(start);
|
||||
|
|
Loading…
Reference in New Issue