mirror of https://github.com/kiwix/libkiwix.git
kiwix::Suggestions::addFTSearchSuggestion()
This commit is contained in:
parent
51bd881211
commit
7a9780eb90
|
@ -138,15 +138,6 @@ std::string renderUrl(const std::string& root, const std::string& urlTemplate)
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string makeFulltextSearchSuggestion(const std::string& lang, const std::string& queryString)
|
|
||||||
{
|
|
||||||
return i18n::expandParameterizedString(lang, "suggest-full-text-search",
|
|
||||||
{
|
|
||||||
{"SEARCH_TERMS", queryString}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
ParameterizedMessage noSuchBookErrorMsg(const std::string& bookName)
|
ParameterizedMessage noSuchBookErrorMsg(const std::string& bookName)
|
||||||
{
|
{
|
||||||
return ParameterizedMessage("no-such-book", { {"BOOK_NAME", bookName} });
|
return ParameterizedMessage("no-such-book", { {"BOOK_NAME", bookName} });
|
||||||
|
@ -717,13 +708,7 @@ std::unique_ptr<Response> InternalServer::handle_suggest(const RequestContext& r
|
||||||
|
|
||||||
/* Propose the fulltext search if possible */
|
/* Propose the fulltext search if possible */
|
||||||
if (archive->hasFulltextIndex()) {
|
if (archive->hasFulltextIndex()) {
|
||||||
MustacheData result;
|
results.addFTSearchSuggestion(request.get_user_language(), queryString);
|
||||||
const auto lang = request.get_user_language();
|
|
||||||
result.set("label", makeFulltextSearchSuggestion(lang, queryString));
|
|
||||||
result.set("value", queryString + " ");
|
|
||||||
result.set("kind", "pattern");
|
|
||||||
result.set("first", results.is_empty_list());
|
|
||||||
results.push_back(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto data = get_default_data();
|
auto data = get_default_data();
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "tools/stringTools.h"
|
#include "tools/stringTools.h"
|
||||||
|
#include "server/i18n.h"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -328,6 +329,21 @@ std::string kiwix::render_template(const std::string& template_str, kainjow::mus
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
std::string makeFulltextSearchSuggestion(const std::string& lang,
|
||||||
|
const std::string& queryString)
|
||||||
|
{
|
||||||
|
return kiwix::i18n::expandParameterizedString(lang, "suggest-full-text-search",
|
||||||
|
{
|
||||||
|
{"SEARCH_TERMS", queryString}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // unnamed namespace
|
||||||
|
|
||||||
kiwix::Suggestions::Suggestions()
|
kiwix::Suggestions::Suggestions()
|
||||||
: kainjow::mustache::data(kainjow::mustache::data::type::list)
|
: kainjow::mustache::data(kainjow::mustache::data::type::list)
|
||||||
{
|
{
|
||||||
|
@ -348,3 +364,14 @@ void kiwix::Suggestions::add(const zim::SuggestionItem& suggestion)
|
||||||
result.set("first", this->is_empty_list());
|
result.set("first", this->is_empty_list());
|
||||||
this->push_back(result);
|
this->push_back(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void kiwix::Suggestions::addFTSearchSuggestion(const std::string& uiLang,
|
||||||
|
const std::string& queryString)
|
||||||
|
{
|
||||||
|
kainjow::mustache::data result;
|
||||||
|
result.set("label", makeFulltextSearchSuggestion(uiLang, queryString));
|
||||||
|
result.set("value", queryString + " ");
|
||||||
|
result.set("kind", "pattern");
|
||||||
|
result.set("first", this->is_empty_list());
|
||||||
|
this->push_back(result);
|
||||||
|
}
|
||||||
|
|
|
@ -78,6 +78,9 @@ namespace kiwix
|
||||||
Suggestions();
|
Suggestions();
|
||||||
|
|
||||||
void add(const zim::SuggestionItem& suggestion);
|
void add(const zim::SuggestionItem& suggestion);
|
||||||
|
|
||||||
|
void addFTSearchSuggestion(const std::string& uiLang,
|
||||||
|
const std::string& query);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue