mirror of https://github.com/kiwix/libkiwix.git
Properly fail when creating XapianSearcher on a zim without embedded index.
The XapianSearcher creation must fail with a exception if we cannot open the xapian database. So, if we try to open a zim and there is no embedded index, we must fail. We raise the custom exception NoXapianIndexInZim in this case.
This commit is contained in:
parent
e3c2a13fa6
commit
e526026407
|
@ -36,18 +36,16 @@ namespace kiwix {
|
||||||
|
|
||||||
/* Open Xapian readable database */
|
/* Open Xapian readable database */
|
||||||
void XapianSearcher::openIndex(const string &directoryPath) {
|
void XapianSearcher::openIndex(const string &directoryPath) {
|
||||||
bool indexInZim = false;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
zim::File zimFile = zim::File(directoryPath);
|
zim::File zimFile = zim::File(directoryPath);
|
||||||
zim::Article xapianArticle = zimFile.getArticle('Z', "/Z/fulltextIndex/xapian");
|
zim::Article xapianArticle = zimFile.getArticle('Z', "/Z/fulltextIndex/xapian");
|
||||||
if (xapianArticle.good())
|
if ( ! xapianArticle.good())
|
||||||
{
|
throw NoXapianIndexInZim();
|
||||||
zim::offset_type dbOffset = xapianArticle.getOffset();
|
zim::offset_type dbOffset = xapianArticle.getOffset();
|
||||||
int databasefd = open(directoryPath.c_str(), O_RDONLY);
|
int databasefd = open(directoryPath.c_str(), O_RDONLY);
|
||||||
lseek(databasefd, dbOffset, SEEK_SET);
|
lseek(databasefd, dbOffset, SEEK_SET);
|
||||||
this->readableDatabase = Xapian::Database(databasefd);
|
this->readableDatabase = Xapian::Database(databasefd);
|
||||||
}
|
|
||||||
} catch (zim::ZimFileFormatError)
|
} catch (zim::ZimFileFormatError)
|
||||||
{
|
{
|
||||||
this->readableDatabase = Xapian::Database(directoryPath);
|
this->readableDatabase = Xapian::Database(directoryPath);
|
||||||
|
|
|
@ -27,6 +27,14 @@ using namespace std;
|
||||||
|
|
||||||
namespace kiwix {
|
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 {
|
class XapianSearcher : public Searcher {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in New Issue