mirror of https://github.com/kiwix/libkiwix.git
Handle book without xapian index.
This commit is contained in:
parent
1962262f94
commit
3641dbf14d
|
@ -566,26 +566,36 @@ std::unique_ptr<Response> InternalServer::handle_search(const RequestContext& re
|
||||||
/* Make the search */
|
/* Make the search */
|
||||||
// Try to get a search from the searchInfo, else build it
|
// Try to get a search from the searchInfo, else build it
|
||||||
std::shared_ptr<zim::Search> search;
|
std::shared_ptr<zim::Search> search;
|
||||||
search = searchCache.getOrPut(searchInfo,
|
try {
|
||||||
[=](){
|
search = searchCache.getOrPut(searchInfo,
|
||||||
std::shared_ptr<zim::Searcher> searcher;
|
[=](){
|
||||||
if (archive) {
|
std::shared_ptr<zim::Searcher> searcher;
|
||||||
searcher = searcherCache.getOrPut(bookId, [=](){ return std::make_shared<zim::Searcher>(*archive);});
|
if (archive) {
|
||||||
} else {
|
searcher = searcherCache.getOrPut(bookId, [=](){ return std::make_shared<zim::Searcher>(*archive);});
|
||||||
for (auto& bookId: mp_library->filter(kiwix::Filter().local(true).valid(true))) {
|
} else {
|
||||||
auto currentArchive = mp_library->getArchiveById(bookId);
|
for (auto& bookId: mp_library->filter(kiwix::Filter().local(true).valid(true))) {
|
||||||
if (currentArchive) {
|
auto currentArchive = mp_library->getArchiveById(bookId);
|
||||||
if (! searcher) {
|
if (currentArchive) {
|
||||||
searcher = std::make_shared<zim::Searcher>(*currentArchive);
|
if (! searcher) {
|
||||||
} else {
|
searcher = std::make_shared<zim::Searcher>(*currentArchive);
|
||||||
searcher->addArchive(*currentArchive);
|
} else {
|
||||||
|
searcher->addArchive(*currentArchive);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return make_shared<zim::Search>(searcher->search(searchInfo.getZimQuery(m_verbose.load())));
|
||||||
}
|
}
|
||||||
return make_shared<zim::Search>(searcher->search(searchInfo.getZimQuery(m_verbose.load())));
|
);
|
||||||
}
|
} catch(std::runtime_error& e) {
|
||||||
);
|
// Searcher->search will throw a runtime error if there is no valid xapian database to do the search.
|
||||||
|
// (in case of zim file not containing a index)
|
||||||
|
auto data = get_default_data();
|
||||||
|
data.set("pattern", encodeDiples(searchInfo.pattern));
|
||||||
|
auto response = ContentResponse::build(*this, RESOURCE::templates::no_search_result_html, data, "text/html; charset=utf-8");
|
||||||
|
response->set_code(MHD_HTTP_NOT_FOUND);
|
||||||
|
return withTaskbarInfo(searchInfo.bookName, archive.get(), std::move(response));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
auto start = 0;
|
auto start = 0;
|
||||||
|
|
Loading…
Reference in New Issue