mirror of https://github.com/kiwix/libkiwix.git
kiwix::Suggestions::add()
This commit is contained in:
parent
f36f1661d5
commit
51bd881211
|
@ -711,18 +711,7 @@ std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& r
|
|||
auto srs = search.getResults(start, count);
|
||||
|
||||
for(auto& suggestion: srs) {
|
||||
MustacheData result;
|
||||
result.set("label", suggestion.getTitle());
|
||||
|
||||
if (suggestion.hasSnippet()) {
|
||||
result.set("label", suggestion.getSnippet());
|
||||
}
|
||||
|
||||
result.set("value", suggestion.getTitle());
|
||||
result.set("kind", "path");
|
||||
result.set("path", suggestion.getPath());
|
||||
result.set("first", results.is_empty_list());
|
||||
results.push_back(result);
|
||||
results.add(suggestion);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include <pugixml.hpp>
|
||||
|
||||
#include <zim/uuid.h>
|
||||
#include <zim/suggestion_iterator.h>
|
||||
|
||||
|
||||
static std::map<std::string, std::string> codeisomapping {
|
||||
|
@ -331,3 +332,19 @@ kiwix::Suggestions::Suggestions()
|
|||
: kainjow::mustache::data(kainjow::mustache::data::type::list)
|
||||
{
|
||||
}
|
||||
|
||||
void kiwix::Suggestions::add(const zim::SuggestionItem& suggestion)
|
||||
{
|
||||
kainjow::mustache::data result;
|
||||
result.set("label", suggestion.getTitle());
|
||||
|
||||
if (suggestion.hasSnippet()) {
|
||||
result.set("label", suggestion.getSnippet());
|
||||
}
|
||||
|
||||
result.set("value", suggestion.getTitle());
|
||||
result.set("kind", "path");
|
||||
result.set("path", suggestion.getPath());
|
||||
result.set("first", this->is_empty_list());
|
||||
this->push_back(result);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,10 @@ namespace pugi {
|
|||
class xml_node;
|
||||
}
|
||||
|
||||
namespace zim {
|
||||
class SuggestionItem;
|
||||
}
|
||||
|
||||
namespace kiwix
|
||||
{
|
||||
std::string nodeToString(const pugi::xml_node& node);
|
||||
|
@ -72,6 +76,8 @@ namespace kiwix
|
|||
{
|
||||
public:
|
||||
Suggestions();
|
||||
|
||||
void add(const zim::SuggestionItem& suggestion);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue