From 6074b5e55713135ce632c52026938c5b257ff952 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Thu, 11 Aug 2016 17:42:51 +0200 Subject: [PATCH] Add support of embedded ft-index in zim for kiwix-serve and kiwix-search. - kiwix-search will try the embedded ft-index if no indexPath is specified in the library.xml or command argument. - kiwix-search also uses xapianSearcher and xapianSearcher needs zimlib, so add zimlib in compilation flag for searcher. - kiwix-serve already depends on zimlib. --- src/common/kiwix/xapianSearcher.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/common/kiwix/xapianSearcher.cpp b/src/common/kiwix/xapianSearcher.cpp index d71bf7406..80dfedf21 100644 --- a/src/common/kiwix/xapianSearcher.cpp +++ b/src/common/kiwix/xapianSearcher.cpp @@ -18,6 +18,12 @@ */ #include "xapianSearcher.h" +#include +#include +#include +#include +#include +#include namespace kiwix { @@ -30,7 +36,22 @@ namespace kiwix { /* Open Xapian readable database */ void XapianSearcher::openIndex(const string &directoryPath) { - this->readableDatabase = Xapian::Database(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); + } + } catch (zim::ZimFileFormatError) + { + this->readableDatabase = Xapian::Database(directoryPath); + } } /* Close Xapian writable database */