9#include "enginedebug.h"
10#include "postingiterator.h"
16IdTreeDB::IdTreeDB(MDB_dbi dbi, MDB_txn* txn)
20 Q_ASSERT(txn !=
nullptr);
24MDB_dbi IdTreeDB::create(MDB_txn* txn)
27 int rc = mdb_dbi_open(txn,
"idtree", MDB_CREATE | MDB_INTEGERKEY, &dbi);
29 qCWarning(ENGINE) <<
"IdTreeDB::create" << mdb_strerror(rc);
36MDB_dbi IdTreeDB::open(MDB_txn* txn)
39 int rc = mdb_dbi_open(txn,
"idtree", MDB_INTEGERKEY, &dbi);
41 qCWarning(ENGINE) <<
"IdTreeDB::open" << mdb_strerror(rc);
53 key.mv_size =
sizeof(quint64);
54 key.mv_data =
static_cast<void*
>(&docId);
57 if (subDocIds.
empty()) {
58 rc = mdb_del(m_txn, m_dbi, &key,
nullptr);
59 if (rc == MDB_NOTFOUND) {
64 val.mv_size = subDocIds.
size() *
sizeof(quint64);
65 val.mv_data =
static_cast<void*
>(
const_cast<quint64*
>(subDocIds.
constData()));
67 rc = mdb_put(m_txn, m_dbi, &key, &val, 0);
70 qCWarning(ENGINE) <<
"IdTreeDB::set" << mdb_strerror(rc);
77 key.mv_size =
sizeof(quint64);
78 key.mv_data =
static_cast<void*
>(&docId);
80 MDB_val val{0,
nullptr};
81 int rc = mdb_get(m_txn, m_dbi, &key, &val);
83 if (rc != MDB_NOTFOUND) {
84 qCDebug(ENGINE) <<
"IdTreeDB::get" << docId << mdb_strerror(rc);
91 memcpy(
list.
data(), val.mv_data, val.mv_size);
102 : m_db(db), m_pos(-1), m_idList(
list) {}
104 quint64 docId()
const override {
105 if (m_pos >= 0 && m_pos < m_resultList.size()) {
106 return m_resultList[m_pos];
111 quint64
next()
override {
112 if (m_resultList.isEmpty() && m_idList.isEmpty()) {
116 if (m_resultList.isEmpty()) {
117 while (!m_idList.isEmpty()) {
118 quint64
id = m_idList.takeLast();
119 m_idList << m_db.get(
id);
122 std::sort(m_resultList.begin(), m_resultList.end());
126 if (m_pos < m_resultList.size()) {
129 m_resultList.clear();
133 if (m_pos < m_resultList.size()) {
134 return m_resultList[m_pos];
152 return new IdTreePostingIterator(*
this, list);
158 mdb_cursor_open(m_txn, m_dbi, &cursor);
160 MDB_val key = {0,
nullptr};
165 int rc = mdb_cursor_get(cursor, &key, &val, MDB_NEXT);
166 if (rc == MDB_NOTFOUND) {
170 qCDebug(ENGINE) <<
"IdTreeDB::toTestMap" << mdb_strerror(rc);
174 const quint64
id = *(
static_cast<quint64*
>(key.mv_data));
177 memcpy(
list.
data(), val.mv_data, val.mv_size);
179 map.insert(
id, list);
182 mdb_cursor_close(cursor);
A PostingIterator is an abstract base class which can be used to iterate over all the "postings" or "...
Implements storage for docIds without any associated data Instantiated for:
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QAction * next(const QObject *recvr, const char *slot, QObject *parent)
const_pointer constData() const const
bool contains(const AT &value) const const
qsizetype size() const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)