9#include "doctermscodec.h"
10#include "enginedebug.h"
14DocumentDB::DocumentDB(MDB_dbi dbi, MDB_txn* txn)
18 Q_ASSERT(txn !=
nullptr);
22DocumentDB::~DocumentDB()
26MDB_dbi DocumentDB::create(
const char* name, MDB_txn* txn)
29 const int rc = mdb_dbi_open(txn, name, MDB_CREATE | MDB_INTEGERKEY, &dbi);
31 qCWarning(ENGINE) <<
"DocumentDB::create" <<
name << mdb_strerror(rc);
38MDB_dbi DocumentDB::open(
const char* name, MDB_txn* txn)
41 const int rc = mdb_dbi_open(txn, name, MDB_INTEGERKEY, &dbi);
43 qCWarning(ENGINE) <<
"DocumentDB::open" <<
name << mdb_strerror(rc);
56 key.mv_size =
sizeof(quint64);
57 key.mv_data =
static_cast<void*
>(&docId);
62 val.mv_size = arr.
size();
63 val.mv_data =
static_cast<void*
>(arr.
data());
65 int rc = mdb_put(m_txn, m_dbi, &key, &val, 0);
67 qCWarning(ENGINE) <<
"DocumentDB::put" << mdb_strerror(rc);
76 key.mv_size =
sizeof(quint64);
77 key.mv_data =
static_cast<void*
>(&docId);
79 MDB_val val{0,
nullptr};
80 int rc = mdb_get(m_txn, m_dbi, &key, &val);
82 qCDebug(ENGINE) <<
"DocumentDB::get" << docId << mdb_strerror(rc);
88 auto result = DocTermsCodec::decode(arr);
89 if (result.isEmpty()) {
90 qCDebug(ENGINE) <<
"Document Terms DB contains corrupt data for " << docId;
95void DocumentDB::del(quint64 docId)
100 key.mv_size =
sizeof(quint64);
101 key.mv_data =
static_cast<void*
>(&docId);
103 int rc = mdb_del(m_txn, m_dbi, &key,
nullptr);
104 if (rc != 0 && rc != MDB_NOTFOUND) {
105 qCDebug(ENGINE) <<
"DocumentDB::del" << docId << mdb_strerror(rc);
109bool DocumentDB::contains(quint64 docId)
114 key.mv_size =
sizeof(quint64);
115 key.mv_data =
static_cast<void*
>(&docId);
118 int rc = mdb_get(m_txn, m_dbi, &key, &val);
120 if (rc != MDB_NOTFOUND) {
121 qCDebug(ENGINE) <<
"DocumentDB::contains" << docId << mdb_strerror(rc);
129uint DocumentDB::size()
132 int rc = mdb_stat(m_txn, m_dbi, &stat);
134 qCDebug(ENGINE) <<
"DocumentDB::size" << mdb_strerror(rc);
138 return stat.ms_entries;
144 mdb_cursor_open(m_txn, m_dbi, &cursor);
146 MDB_val key = {0,
nullptr};
151 int rc = mdb_cursor_get(cursor, &key, &val, MDB_NEXT);
152 if (rc == MDB_NOTFOUND) {
156 qCWarning(ENGINE) <<
"DocumentDB::toTestMap" << mdb_strerror(rc);
160 const quint64
id = *(
static_cast<quint64*
>(key.mv_data));
165 mdb_cursor_close(cursor);
Implements storage for docIds without any associated data Instantiated for:
KIOCORE_EXPORT StatJob * stat(const QUrl &url, JobFlags flags=DefaultFlags)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QString name(StandardAction id)
QByteArray fromRawData(const char *data, qsizetype size)
qsizetype size() const const
bool isEmpty() const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)