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);
|
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.
|
* Set protocol prefix.
|
||||||
|
@ -112,7 +112,7 @@ class SearchRenderer
|
||||||
zim::SearchResultSet m_srs;
|
zim::SearchResultSet m_srs;
|
||||||
NameMapper* mp_nameMapper;
|
NameMapper* mp_nameMapper;
|
||||||
Library* mp_library;
|
Library* mp_library;
|
||||||
std::string searchContent;
|
std::set<std::string> searchBookIds;
|
||||||
std::string searchPattern;
|
std::string searchPattern;
|
||||||
std::string protocolPrefix;
|
std::string protocolPrefix;
|
||||||
std::string searchProtocolPrefix;
|
std::string searchProtocolPrefix;
|
||||||
|
|
|
@ -71,9 +71,9 @@ void SearchRenderer::setSearchPattern(const std::string& pattern)
|
||||||
searchPattern = 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)
|
void SearchRenderer::setProtocolPrefix(const std::string& prefix)
|
||||||
|
@ -90,13 +90,15 @@ kainjow::mustache::data buildQueryData
|
||||||
(
|
(
|
||||||
const std::string& searchProtocolPrefix,
|
const std::string& searchProtocolPrefix,
|
||||||
const std::string& pattern,
|
const std::string& pattern,
|
||||||
const std::string& searchContent
|
const std::set<std::string>& bookIds
|
||||||
) {
|
) {
|
||||||
kainjow::mustache::data query;
|
kainjow::mustache::data query;
|
||||||
query.set("pattern", kiwix::encodeDiples(pattern));
|
query.set("pattern", kiwix::encodeDiples(pattern));
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << searchProtocolPrefix << "?pattern=" << urlEncode(pattern, true);
|
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());
|
query.set("unpaginatedQuery", ss.str());
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -197,7 +199,7 @@ std::string SearchRenderer::getHtml()
|
||||||
kainjow::mustache::data query = buildQueryData(
|
kainjow::mustache::data query = buildQueryData(
|
||||||
searchProtocolPrefix,
|
searchProtocolPrefix,
|
||||||
searchPattern,
|
searchPattern,
|
||||||
searchContent
|
searchBookIds
|
||||||
);
|
);
|
||||||
|
|
||||||
std::string template_str = RESOURCE::templates::search_result_html;
|
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,
|
SearchRenderer renderer(search->getResults(start, pageLength), mp_nameMapper, mp_library, start,
|
||||||
search->getEstimatedMatches());
|
search->getEstimatedMatches());
|
||||||
renderer.setSearchPattern(searchInfo.pattern);
|
renderer.setSearchPattern(searchInfo.pattern);
|
||||||
//[TODO]
|
renderer.setSearchBookIds(bookIds);
|
||||||
//renderer.setSearchContent(searchInfo.bookNames);
|
|
||||||
renderer.setProtocolPrefix(m_root + "/");
|
renderer.setProtocolPrefix(m_root + "/");
|
||||||
renderer.setSearchProtocolPrefix(m_root + "/search");
|
renderer.setSearchProtocolPrefix(m_root + "/search");
|
||||||
renderer.setPageLength(pageLength);
|
renderer.setPageLength(pageLength);
|
||||||
|
|
|
@ -1611,7 +1611,7 @@ TEST_F(TaskbarlessServerTest, searchResults)
|
||||||
|
|
||||||
static std::string makeUrl(const std::string pattern, int start, size_t resultsPerPage)
|
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 ) {
|
if ( start >= 0 ) {
|
||||||
url += "&start=" + to_string(start);
|
url += "&start=" + to_string(start);
|
||||||
|
|
Loading…
Reference in New Issue