From 56434de79ef1a9896d7b37f88ee33ed0f1aeb186 Mon Sep 17 00:00:00 2001 From: Maneesh P M Date: Sat, 8 May 2021 21:26:17 +0530 Subject: [PATCH] Set label to title snippet if present With openzim/libzim#545 we now support snippet generation of titles which can be used as the display label on the ui for highlighted titles via the "label" field. The old version used plain title which is still available in the value field. --- src/reader.cpp | 1 + src/server/internalServer.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/reader.cpp b/src/reader.cpp index 1abc9eadb..48b826500 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -510,6 +510,7 @@ bool Reader::searchSuggestionsSmart(const string& prefix, suggestion.push_back(current.getTitle()); suggestion.push_back(current.getPath()); suggestion.push_back(kiwix::normalize(current.getTitle())); + suggestion.push_back(current.getSnippet()); results.push_back(suggestion); } retVal = true; diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index f28c3df03..381a56c1d 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -415,6 +415,11 @@ std::unique_ptr InternalServer::handle_suggest(const RequestContext& r for(auto& suggestion:suggestions) { MustacheData result; result.set("label", suggestion[0]); + + if (!suggestion[3].empty()) { + result.set("label", suggestion[3]); + } + result.set("value", suggestion[0]); result.set("kind", "path"); result.set("path", suggestion[1]);