8#include "xapiandatabase.h"
9#include "xapiandocument.h"
11#include "akonadi_search_xapian_debug.h"
14#if defined(HAVE_MALLOC_H)
24 : m_writeOnly(writeOnly)
32 m_db =
new Xapian::Database(m_path);
33 }
catch (
const Xapian::DatabaseError &err) {
34 qCWarning(AKONADI_SEARCH_XAPIAN_LOG) <<
"Serious Error: " << err.get_error_string();
35 qCWarning(AKONADI_SEARCH_XAPIAN_LOG) << err.get_msg().c_str() << err.get_context().c_str() << err.get_description().c_str();
41 m_wDb = createWritableDb();
45XapianDatabase::~XapianDatabase()
50void XapianDatabase::replaceDocument(uint
id,
const XapianDocument &doc)
52 replaceDocument(
id, doc.doc());
55void XapianDatabase::replaceDocument(uint
id,
const Xapian::Document &doc)
59 m_wDb.replace_document(
id, doc);
60 }
catch (
const Xapian::Error &) {
64 m_docsToAdd << qMakePair(
id, doc);
67void XapianDatabase::deleteDocument(uint
id)
75 m_wDb.delete_document(
id);
76 }
catch (
const Xapian::Error &) {
93 }
catch (
const Xapian::Error &err) {
94 qCWarning(AKONADI_SEARCH_XAPIAN_LOG) << err.get_error_string();
103 Xapian::WritableDatabase wdb = createWritableDb();
105 qCDebug(AKONADI_SEARCH_XAPIAN_LOG) <<
"Adding:" << m_docsToAdd.
size() <<
"docs";
106 for (
const DocIdPair &doc : std::as_const(m_docsToAdd)) {
108 wdb.replace_document(doc.first, doc.second);
109 }
catch (
const Xapian::Error &) {
113 qCDebug(AKONADI_SEARCH_XAPIAN_LOG) <<
"Removing:" << m_docsToRemove.
size() <<
"docs";
114 for (Xapian::docid
id : std::as_const(m_docsToRemove)) {
116 wdb.delete_document(
id);
117 }
catch (
const Xapian::Error &) {
124 }
catch (
const Xapian::Error &err) {
125 qCWarning(AKONADI_SEARCH_XAPIAN_LOG) << err.get_error_string();
127 qCDebug(AKONADI_SEARCH_XAPIAN_LOG) <<
"Xapian Committed";
130 m_docsToRemove.
clear();
132#if defined(HAVE_MALLOC_TRIM)
140 Xapian::Document xdoc;
142 xdoc = m_wDb.get_document(
id);
144 xdoc = m_db->get_document(
id);
147 }
catch (
const Xapian::DatabaseModifiedError &) {
150 }
catch (
const Xapian::Error &) {
155Xapian::WritableDatabase XapianDatabase::createWritableDb()
159 for (
int i = 1; i <= 20; ++i) {
161 Xapian::WritableDatabase wdb(m_path, Xapian::DB_CREATE_OR_OPEN);
163 }
catch (
const Xapian::DatabaseLockError &) {
164 std::this_thread::sleep_for(std::chrono::milliseconds(i * 50));
165 }
catch (
const Xapian::DatabaseModifiedError &) {
166 std::this_thread::sleep_for(std::chrono::milliseconds(i * 50));
167 }
catch (
const Xapian::DatabaseCreateError &err) {
168 qCDebug(AKONADI_SEARCH_XAPIAN_LOG) << err.get_error_string();
170 }
catch (
const Xapian::DatabaseCorruptError &err) {
171 qCWarning(AKONADI_SEARCH_XAPIAN_LOG) <<
"Database Corrupted - What did you do?";
172 qCWarning(AKONADI_SEARCH_XAPIAN_LOG) << err.get_error_string();
175 qCWarning(AKONADI_SEARCH_XAPIAN_LOG) <<
"Bananana Error";
180 qCWarning(AKONADI_SEARCH_XAPIAN_LOG) <<
"Could not obtain lock for Xapian Database. This is bad";
bool haveChanges() const
Returns true if the XapianDatabase has changes which need to be committed.
XapianDatabase(const QString &path, bool writeOnly=false)
Create the Xapian db at path path.
void commit()
Commit all the pending changes.
This class is just a light wrapper over Xapian::Document which provides nice Qt apis.
Akonadi search infrastructure.
bool mkpath(const QString &dirPath) const const
bool isEmpty() const const
qsizetype size() const const
std::string toStdString() const const