8#include "enginedebug.h"
10#include "positioncodec.h"
11#include "positioninfo.h"
12#include "postingiterator.h"
13#include "vectorpositioninfoiterator.h"
17PositionDB::PositionDB(MDB_dbi dbi, MDB_txn* txn)
21 Q_ASSERT(txn !=
nullptr);
25PositionDB::~PositionDB()
29MDB_dbi PositionDB::create(MDB_txn* txn)
32 int rc = mdb_dbi_open(txn,
"positiondb", MDB_CREATE, &dbi);
34 qCWarning(ENGINE) <<
"PositionDB::create" << mdb_strerror(rc);
41MDB_dbi PositionDB::open(MDB_txn* txn)
44 int rc = mdb_dbi_open(txn,
"positiondb", 0, &dbi);
46 qCWarning(ENGINE) <<
"PositionDB::open" << mdb_strerror(rc);
59 key.mv_size = term.
size();
60 key.mv_data =
static_cast<void*
>(
const_cast<char*
>(term.
constData()));
65 val.mv_size = data.
size();
66 val.mv_data =
static_cast<void*
>(data.
data());
68 int rc = mdb_put(m_txn, m_dbi, &key, &val, 0);
70 qCWarning(ENGINE) <<
"PositionDB::put" << mdb_strerror(rc);
79 key.mv_size = term.
size();
80 key.mv_data =
static_cast<void*
>(
const_cast<char*
>(term.
constData()));
82 MDB_val val{0,
nullptr};
83 int rc = mdb_get(m_txn, m_dbi, &key, &val);
85 if (rc != MDB_NOTFOUND) {
86 qCDebug(ENGINE) <<
"PositionDB::get" << term << mdb_strerror(rc);
93 return PositionCodec::decode(data);
101 key.mv_size = term.
size();
102 key.mv_data =
static_cast<void*
>(
const_cast<char*
>(term.
constData()));
104 int rc = mdb_del(m_txn, m_dbi, &key,
nullptr);
105 if (rc != 0 && rc != MDB_NOTFOUND) {
106 qCDebug(ENGINE) <<
"PositionDB::del" << term << mdb_strerror(rc);
114VectorPositionInfoIterator* PositionDB::iter(
const QByteArray& term)
119 key.mv_size = term.
size();
120 key.mv_data =
static_cast<void*
>(
const_cast<char*
>(term.
constData()));
122 MDB_val val{0,
nullptr};
123 int rc = mdb_get(m_txn, m_dbi, &key, &val);
125 qCDebug(ENGINE) <<
"PositionDB::iter" << term << mdb_strerror(rc);
129 QByteArray ba(
static_cast<char*
>(val.mv_data), val.mv_size);
130 return new VectorPositionInfoIterator(PositionCodec::decode(ba));
136 mdb_cursor_open(m_txn, m_dbi, &cursor);
138 MDB_val key = {0,
nullptr};
143 int rc = mdb_cursor_get(cursor, &key, &val, MDB_NEXT);
144 if (rc == MDB_NOTFOUND) {
148 qCDebug(ENGINE) <<
"PositionDB::toTestMap" << mdb_strerror(rc);
152 const QByteArray ba(
static_cast<char*
>(key.mv_data), key.mv_size);
153 const QByteArray data(
static_cast<char*
>(val.mv_data), val.mv_size);
155 map.insert(ba, vinfo);
158 mdb_cursor_close(cursor);
Implements storage for docIds without any associated data Instantiated for:
KIOCORE_EXPORT QStringList list(const QString &fileClass)
const char * constData() const const
QByteArray fromRawData(const char *data, qsizetype size)
bool isEmpty() const const
qsizetype size() const const
bool isEmpty() const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)