diff --git a/src/common/kiwix/xapianSearcher.cpp b/src/common/kiwix/xapianSearcher.cpp index 80dfedf21..6d895aa6d 100644 --- a/src/common/kiwix/xapianSearcher.cpp +++ b/src/common/kiwix/xapianSearcher.cpp @@ -36,18 +36,16 @@ namespace kiwix { /* Open Xapian readable database */ void XapianSearcher::openIndex(const string &directoryPath) { - bool indexInZim = false; try { zim::File zimFile = zim::File(directoryPath); - zim::Article xapianArticle = zimFile.getArticle('Z', "/Z/fulltextIndex/xapian"); - if (xapianArticle.good()) - { - zim::offset_type dbOffset = xapianArticle.getOffset(); - int databasefd = open(directoryPath.c_str(), O_RDONLY); - lseek(databasefd, dbOffset, SEEK_SET); - this->readableDatabase = Xapian::Database(databasefd); - } + zim::Article xapianArticle = zimFile.getArticle('Z', "/fulltextIndex/xapian"); + if ( ! xapianArticle.good()) + throw NoXapianIndexInZim(); + zim::offset_type dbOffset = xapianArticle.getOffset(); + int databasefd = open(directoryPath.c_str(), O_RDONLY); + lseek(databasefd, dbOffset, SEEK_SET); + this->readableDatabase = Xapian::Database(databasefd); } catch (zim::ZimFileFormatError) { this->readableDatabase = Xapian::Database(directoryPath); diff --git a/src/common/kiwix/xapianSearcher.h b/src/common/kiwix/xapianSearcher.h index e01283be7..3fb24b29e 100644 --- a/src/common/kiwix/xapianSearcher.h +++ b/src/common/kiwix/xapianSearcher.h @@ -27,6 +27,14 @@ using namespace std; namespace kiwix { + class NoXapianIndexInZim: public exception + { + virtual const char* what() const throw() + { + return "There is no fulltext index in the zim file"; + } + }; + class XapianSearcher : public Searcher { public: