From cd623ce3580c5884564725935fb7bb205e0309ae Mon Sep 17 00:00:00 2001 From: kelson42 Date: Sun, 2 Oct 2016 18:29:49 +0200 Subject: [PATCH] Fix crash with ZIM files without FT indexes --- src/server/kiwix-serve.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index 161be4a..3fd3931 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -572,20 +572,13 @@ int main(int argc, char **argv) { } } else { std::vector::iterator it; - for (it = zimPathes.begin(); it != zimPathes.end(); it++) - { + for (it = zimPathes.begin(); it != zimPathes.end(); it++) { if (!libraryManager.addBookFromPath(*it, *it, "", false)) { cerr << "Unable to add the ZIM file '" << *it << "' to the internal library." << endl; exit(1); } } if (!indexPath.empty()) { - try { - new kiwix::XapianSearcher(indexPath); - } catch (...) { - cerr << "Unable to open the search index '" << indexPath << "'." << endl; - } - libraryManager.setBookIndex(libraryManager.getBooksIds()[0], indexPath); } } @@ -618,17 +611,20 @@ int main(int argc, char **argv) { /* Try to instanciate the zim index. * If there is no specified indexPath, try to open the * embedded index in the zim. */ - if (indexPath.empty()) { - indexPath = zimPath; + if (indexPath.empty() && reader->hasFulltextIndex()) { + indexPath = zimPath; } - try { - kiwix::Searcher *searcher = new kiwix::XapianSearcher(indexPath); - searcher->setProtocolPrefix("/"); - searcher->setSearchProtocolPrefix("/search?"); - searcher->setContentHumanReadableId(humanReadableId); - searchers[humanReadableId] = searcher; - } catch (...) { - cerr << "Unable to open the search index '" << indexPath << "'." << endl; + + if (!indexPath.empty()) { + try { + kiwix::Searcher *searcher = new kiwix::XapianSearcher(indexPath); + searcher->setProtocolPrefix("/"); + searcher->setSearchProtocolPrefix("/search?"); + searcher->setContentHumanReadableId(humanReadableId); + searchers[humanReadableId] = searcher; + } catch (...) { + cerr << "Unable to open the search index '" << indexPath << "'." << endl; + } } } }