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 <string>
|
||||||
#include <zim/search.h>
|
#include <zim/search.h>
|
||||||
|
#include <library.h>
|
||||||
|
|
||||||
namespace kiwix
|
namespace kiwix
|
||||||
{
|
{
|
||||||
|
@ -50,10 +51,12 @@ class SearchRenderer
|
||||||
*
|
*
|
||||||
* @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
|
||||||
|
* 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
|
||||||
*/
|
*/
|
||||||
SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper,
|
SearchRenderer(zim::SearchResultSet srs, NameMapper* mapper, Library* library,
|
||||||
unsigned int start, unsigned int estimatedResultCount);
|
unsigned int start, unsigned int estimatedResultCount);
|
||||||
|
|
||||||
~SearchRenderer();
|
~SearchRenderer();
|
||||||
|
@ -91,6 +94,7 @@ class SearchRenderer
|
||||||
std::string beautifyInteger(const unsigned int number);
|
std::string beautifyInteger(const unsigned int number);
|
||||||
zim::SearchResultSet m_srs;
|
zim::SearchResultSet m_srs;
|
||||||
NameMapper* mp_nameMapper;
|
NameMapper* mp_nameMapper;
|
||||||
|
Library* mp_library;
|
||||||
std::string searchContent;
|
std::string searchContent;
|
||||||
std::string searchPattern;
|
std::string searchPattern;
|
||||||
std::string protocolPrefix;
|
std::string protocolPrefix;
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
#include "library.h"
|
#include "library.h"
|
||||||
#include "name_mapper.h"
|
#include "name_mapper.h"
|
||||||
|
|
||||||
|
#include "tools/archiveTools.h"
|
||||||
|
|
||||||
#include <zim/search.h>
|
#include <zim/search.h>
|
||||||
|
|
||||||
#include <mustache.hpp>
|
#include <mustache.hpp>
|
||||||
|
@ -45,10 +47,11 @@ SearchRenderer::SearchRenderer(Searcher* searcher, NameMapper* mapper)
|
||||||
resultStart(searcher->getResultStart())
|
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)
|
unsigned int start, unsigned int estimatedResultCount)
|
||||||
: m_srs(srs),
|
: m_srs(srs),
|
||||||
mp_nameMapper(mapper),
|
mp_nameMapper(mapper),
|
||||||
|
mp_library(library),
|
||||||
protocolPrefix("zim://"),
|
protocolPrefix("zim://"),
|
||||||
searchProtocolPrefix("search://?"),
|
searchProtocolPrefix("search://?"),
|
||||||
estimatedResultCount(estimatedResultCount),
|
estimatedResultCount(estimatedResultCount),
|
||||||
|
@ -90,6 +93,10 @@ std::string SearchRenderer::getHtml()
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
s << it.getZimId();
|
s << it.getZimId();
|
||||||
result.set("resultContentId", mp_nameMapper->getNameForId(s.str()));
|
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) {
|
if (it.getWordCount() >= 0) {
|
||||||
result.set("wordCount", kiwix::beautifyInteger(it.getWordCount()));
|
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);
|
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());
|
search.getEstimatedMatches());
|
||||||
renderer.setSearchPattern(patternString);
|
renderer.setSearchPattern(patternString);
|
||||||
renderer.setSearchContent(bookName);
|
renderer.setSearchContent(bookName);
|
||||||
|
|
|
@ -57,6 +57,11 @@
|
||||||
font-size: 100%;
|
font-size: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.book-title {
|
||||||
|
color: #662200;
|
||||||
|
font-size: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
|
@ -120,6 +125,9 @@
|
||||||
{{#snippet}}
|
{{#snippet}}
|
||||||
<cite>{{>snippet}}...</cite>
|
<cite>{{>snippet}}...</cite>
|
||||||
{{/snippet}}
|
{{/snippet}}
|
||||||
|
{{#bookTitle}}
|
||||||
|
<div class="book-title">from {{bookTitle}}</div>
|
||||||
|
{{/bookTitle}}
|
||||||
{{#wordCount}}
|
{{#wordCount}}
|
||||||
<div class="informations">{{wordCount}} words</div>
|
<div class="informations">{{wordCount}} words</div>
|
||||||
{{/wordCount}}
|
{{/wordCount}}
|
||||||
|
|
Loading…
Reference in New Issue