mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-28 05:49:35 +00:00
Merge pull request #274 from kiwix/embedded_zim_support
Add support of embedded ft-index in zim for kiwix-serve and kiwix-search.
This commit is contained in:
@ -18,6 +18,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "xapianSearcher.h"
|
#include "xapianSearcher.h"
|
||||||
|
#include <zim/zim.h>
|
||||||
|
#include <zim/file.h>
|
||||||
|
#include <zim/article.h>
|
||||||
|
#include <zim/error.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace kiwix {
|
namespace kiwix {
|
||||||
|
|
||||||
@ -30,7 +36,22 @@ namespace kiwix {
|
|||||||
|
|
||||||
/* Open Xapian readable database */
|
/* Open Xapian readable database */
|
||||||
void XapianSearcher::openIndex(const string &directoryPath) {
|
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 */
|
/* Close Xapian writable database */
|
||||||
|
Reference in New Issue
Block a user