From 51bd881211506b507597aca34a10c33844f8e7af Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Thu, 10 Nov 2022 13:58:22 +0400 Subject: [PATCH] kiwix::Suggestions::add() --- src/server/internalServer.cpp | 13 +------------ src/tools/otherTools.cpp | 17 +++++++++++++++++ src/tools/otherTools.h | 6 ++++++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 163e633f2..13b82a2b1 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -711,18 +711,7 @@ std::unique_ptr 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); } diff --git a/src/tools/otherTools.cpp b/src/tools/otherTools.cpp index 99458349d..82c80c9c3 100644 --- a/src/tools/otherTools.cpp +++ b/src/tools/otherTools.cpp @@ -38,6 +38,7 @@ #include #include +#include static std::map 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); +} diff --git a/src/tools/otherTools.h b/src/tools/otherTools.h index f16f2ab6a..80d9582a8 100644 --- a/src/tools/otherTools.h +++ b/src/tools/otherTools.h @@ -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); }; }