Deal with new glass/single_file Xapian indexes

This commit is contained in:
Kelson 2016-06-20 23:35:13 +02:00
parent 8ae2630a94
commit d5e5cd9340
4 changed files with 22 additions and 11 deletions

View File

@ -246,7 +246,7 @@ namespace kiwix {
/* Test if the thread should be cancelled */ /* Test if the thread should be cancelled */
pthread_testcancel(); pthread_testcancel();
} }
self->indexingPostlude(); self->indexingPostlude(self->getIndexPath());
/* Write content id file */ /* Write content id file */
string path = appendToDirectory(self->getIndexPath(), "content.id"); string path = appendToDirectory(self->getIndexPath(), "content.id");

View File

@ -76,7 +76,7 @@ namespace kiwix {
const string &size, const string &size,
const string &wordCount) = 0; const string &wordCount) = 0;
virtual void flush() = 0; virtual void flush() = 0;
virtual void indexingPostlude() = 0; virtual void indexingPostlude(const string indexPath) = 0;
/* Stop words */ /* Stop words */
std::vector<std::string> stopWords; std::vector<std::string> stopWords;

View File

@ -30,7 +30,7 @@ namespace kiwix {
} }
void XapianIndexer::indexingPrelude(const string indexPath) { void XapianIndexer::indexingPrelude(const string indexPath) {
this->writableDatabase = Xapian::WritableDatabase(indexPath, Xapian::DB_CREATE_OR_OVERWRITE); this->writableDatabase = Xapian::WritableDatabase(indexPath+".tmp", Xapian::DB_CREATE_OR_OVERWRITE | Xapian::DB_BACKEND_GLASS);
this->writableDatabase.begin_transaction(true); this->writableDatabase.begin_transaction(true);
/* Insert the stopwords */ /* Insert the stopwords */
@ -87,14 +87,25 @@ namespace kiwix {
this->writableDatabase.begin_transaction(true); this->writableDatabase.begin_transaction(true);
} }
void XapianIndexer::indexingPostlude() { void XapianIndexer::indexingPostlude(const string indexPath) {
this->flush(); this->flush();
this->writableDatabase.commit_transaction(); this->writableDatabase.commit_transaction();
#ifdef _WIN32 #ifdef _WIN32
this->writableDatabase.close(); this->writableDatabase.close();
#endif #endif
// commit is not available is old version of xapian and seems not mandatory there /* Compacting the index */
// this->writableDatabase.commit(); Xapian::Compactor compactor;
try {
Xapian::Database src;
src.add_database(Xapian::Database(indexPath+".tmp"));
src.compact(indexPath, Xapian::Compactor::FULL | Xapian::DBCOMPACT_SINGLE_FILE, 0, compactor);
} catch (const Xapian::Error &error) {
cerr << indexPath << ": " << error.get_description() << endl;
exit(1);
} catch (const char * msg) {
cerr << indexPath << ": " << msg << endl;
exit(1);
}
} }
} }

View File

@ -43,7 +43,7 @@ namespace kiwix {
const string &size, const string &size,
const string &wordCount); const string &wordCount);
void flush(); void flush();
void indexingPostlude(); void indexingPostlude(const string indexPath);
Xapian::WritableDatabase writableDatabase; Xapian::WritableDatabase writableDatabase;
Xapian::Stem stemmer; Xapian::Stem stemmer;