mirror of https://github.com/kiwix/libkiwix.git
Merge pull request #705 from thavelick/book_title_in_search_results
Add book titles to search results
This commit is contained in:
commit
892db07a2d
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <string>
|
||||
#include <zim/search.h>
|
||||
#include <library.h>
|
||||
|
||||
namespace kiwix
|
||||
{
|
||||
|
@ -50,10 +51,12 @@ class SearchRenderer
|
|||
*
|
||||
* @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 estimatedResultCount The estimatedResultCount of the whole search
|
||||
*/
|
||||
SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper,
|
||||
SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper, Library* library,
|
||||
unsigned int start, unsigned int estimatedResultCount);
|
||||
|
||||
~SearchRenderer();
|
||||
|
@ -91,6 +94,7 @@ class SearchRenderer
|
|||
std::string beautifyInteger(const unsigned int number);
|
||||
zim::SearchResultSet m_srs;
|
||||
NameMapper* mp_nameMapper;
|
||||
Library* mp_library;
|
||||
std::string searchContent;
|
||||
std::string searchPattern;
|
||||
std::string protocolPrefix;
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include "library.h"
|
||||
#include "name_mapper.h"
|
||||
|
||||
#include "tools/archiveTools.h"
|
||||
|
||||
#include <zim/search.h>
|
||||
|
||||
#include <mustache.hpp>
|
||||
|
@ -45,10 +47,11 @@ SearchRenderer::SearchRenderer(Searcher* searcher, NameMapper* mapper)
|
|||
resultStart(searcher->getResultStart())
|
||||
{}
|
||||
|
||||
SearchRenderer::SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper,
|
||||
SearchRenderer::SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper, Library* library,
|
||||
unsigned int start, unsigned int estimatedResultCount)
|
||||
: m_srs(srs),
|
||||
mp_nameMapper(mapper),
|
||||
mp_library(library),
|
||||
protocolPrefix("zim://"),
|
||||
searchProtocolPrefix("search://?"),
|
||||
estimatedResultCount(estimatedResultCount),
|
||||
|
@ -90,6 +93,10 @@ std::string SearchRenderer::getHtml()
|
|||
std::ostringstream s;
|
||||
s << it.getZimId();
|
||||
result.set("resultContentId", mp_nameMapper->getNameForId(s.str()));
|
||||
std::shared_ptr<zim::Archive> archive;
|
||||
try {
|
||||
result.set("bookTitle", mp_library->getBookById(s.str()).getTitle());
|
||||
} catch (const std::out_of_range& e) {}
|
||||
|
||||
if (it.getWordCount() >= 0) {
|
||||
result.set("wordCount", kiwix::beautifyInteger(it.getWordCount()));
|
||||
|
|
|
@ -562,7 +562,7 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
|
|||
}
|
||||
|
||||
zim::Search search = searcher->search(query);
|
||||
SearchRenderer renderer(search.getResults(start, pageLength), mp_nameMapper, start,
|
||||
SearchRenderer renderer(search.getResults(start, pageLength), mp_nameMapper, mp_library, start,
|
||||
search.getEstimatedMatches());
|
||||
renderer.setSearchPattern(patternString);
|
||||
renderer.setSearchContent(bookName);
|
||||
|
|
|
@ -57,6 +57,11 @@
|
|||
font-size: 100%;
|
||||
}
|
||||
|
||||
.book-title {
|
||||
color: #662200;
|
||||
font-size: 100%;
|
||||
}
|
||||
|
||||
.footer {
|
||||
padding: 0;
|
||||
margin-top: 1em;
|
||||
|
@ -120,6 +125,9 @@
|
|||
{{#snippet}}
|
||||
<cite>{{>snippet}}...</cite>
|
||||
{{/snippet}}
|
||||
{{#bookTitle}}
|
||||
<div class="book-title">from {{bookTitle}}</div>
|
||||
{{/bookTitle}}
|
||||
{{#wordCount}}
|
||||
<div class="informations">{{wordCount}} words</div>
|
||||
{{/wordCount}}
|
||||
|
|
Loading…
Reference in New Issue