kiwix::Suggestions::getJSON()

This commit is contained in:
Veloman Yunkan 2022-11-10 14:16:58 +04:00
parent 7a9780eb90
commit abcd4ade99
3 changed files with 12 additions and 5 deletions

View File

@ -711,11 +711,7 @@ std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& r
results.addFTSearchSuggestion(request.get_user_language(), queryString);
}
auto data = get_default_data();
data.set("suggestions", results);
auto response = ContentResponse::build(*this, RESOURCE::templates::suggestion_json, data, "application/json; charset=utf-8");
return std::move(response);
return ContentResponse::build(*this, results.getJSON(), "application/json; charset=utf-8");
}
std::unique_ptr<Response> InternalServer::handle_viewer_settings(const RequestContext& request)

View File

@ -33,6 +33,7 @@
#include "tools/stringTools.h"
#include "server/i18n.h"
#include "libkiwix-resources.h"
#include <map>
#include <sstream>
@ -375,3 +376,11 @@ void kiwix::Suggestions::addFTSearchSuggestion(const std::string& uiLang,
result.set("first", this->is_empty_list());
this->push_back(result);
}
std::string kiwix::Suggestions::getJSON() const
{
kainjow::mustache::data data;
data.set("suggestions", *this);
return render_template(RESOURCE::templates::suggestion_json, data);
}

View File

@ -81,6 +81,8 @@ namespace kiwix
void addFTSearchSuggestion(const std::string& uiLang,
const std::string& query);
std::string getJSON() const;
};
}