mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #718 from kiwix/fix_booktitle_renderer
Fix search rendered for book title
This commit is contained in:
commit
cfab560d74
|
@ -49,10 +49,24 @@ class SearchRenderer
|
||||||
/**
|
/**
|
||||||
* Construct a SearchRenderer from a SearchResultSet.
|
* Construct a SearchRenderer from a SearchResultSet.
|
||||||
*
|
*
|
||||||
|
* The constructed version of the SearchRenderer will not introduce
|
||||||
|
* the book name for each result. It is better to use the other constructor
|
||||||
|
* with a Library pointer to have a better html page.
|
||||||
|
*
|
||||||
* @param srs The `SearchResultSet` to render.
|
* @param srs The `SearchResultSet` to render.
|
||||||
* @param mapper The `NameMapper` to use to do the rendering.
|
* @param mapper The `NameMapper` to use to do the rendering.
|
||||||
* @param library The `Library` to use to look up book details for search
|
* @param start The start offset used for the srs.
|
||||||
* results
|
* @param estimatedResultCount The estimatedResultCount of the whole search
|
||||||
|
*/
|
||||||
|
SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper,
|
||||||
|
unsigned int start, unsigned int estimatedResultCount);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a SearchRenderer from a SearchResultSet.
|
||||||
|
*
|
||||||
|
* @param srs The `SearchResultSet` to render.
|
||||||
|
* @param mapper The `NameMapper` to use to do the rendering.
|
||||||
|
* @param library The `Library` to use to look up book details for search results.
|
||||||
* @param start The start offset used for the srs.
|
* @param start The start offset used for the srs.
|
||||||
* @param estimatedResultCount The estimatedResultCount of the whole search
|
* @param estimatedResultCount The estimatedResultCount of the whole search
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -39,12 +39,17 @@ namespace kiwix
|
||||||
|
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
SearchRenderer::SearchRenderer(Searcher* searcher, NameMapper* mapper)
|
SearchRenderer::SearchRenderer(Searcher* searcher, NameMapper* mapper)
|
||||||
: m_srs(searcher->getSearchResultSet()),
|
: SearchRenderer(
|
||||||
mp_nameMapper(mapper),
|
searcher->getSearchResultSet(),
|
||||||
protocolPrefix("zim://"),
|
mapper,
|
||||||
searchProtocolPrefix("search://?"),
|
nullptr,
|
||||||
estimatedResultCount(searcher->getEstimatedResultCount()),
|
searcher->getEstimatedResultCount(),
|
||||||
resultStart(searcher->getResultStart())
|
searcher->getResultStart())
|
||||||
|
{}
|
||||||
|
|
||||||
|
SearchRenderer::SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper,
|
||||||
|
unsigned int start, unsigned int estimatedResultCount)
|
||||||
|
: SearchRenderer(srs, mapper, nullptr, start, estimatedResultCount)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
SearchRenderer::SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper, Library* library,
|
SearchRenderer::SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper, Library* library,
|
||||||
|
@ -90,13 +95,13 @@ std::string SearchRenderer::getHtml()
|
||||||
result.set("title", it.getTitle());
|
result.set("title", it.getTitle());
|
||||||
result.set("url", it.getPath());
|
result.set("url", it.getPath());
|
||||||
result.set("snippet", it.getSnippet());
|
result.set("snippet", it.getSnippet());
|
||||||
std::ostringstream s;
|
std::string zim_id(it.getZimId());
|
||||||
s << it.getZimId();
|
result.set("resultContentId", mp_nameMapper->getNameForId(zim_id));
|
||||||
result.set("resultContentId", mp_nameMapper->getNameForId(s.str()));
|
if (!mp_library) {
|
||||||
std::shared_ptr<zim::Archive> archive;
|
result.set("bookTitle", kainjow::mustache::data(false));
|
||||||
try {
|
} else {
|
||||||
result.set("bookTitle", mp_library->getBookById(s.str()).getTitle());
|
result.set("bookTitle", mp_library->getBookById(zim_id).getTitle());
|
||||||
} catch (const std::out_of_range& e) {}
|
}
|
||||||
|
|
||||||
if (it.getWordCount() >= 0) {
|
if (it.getWordCount() >= 0) {
|
||||||
result.set("wordCount", kiwix::beautifyInteger(it.getWordCount()));
|
result.set("wordCount", kiwix::beautifyInteger(it.getWordCount()));
|
||||||
|
|
Loading…
Reference in New Issue