9#include "enginedebug.h"
10#include "vectorpostingiterator.h"
15MTimeDB::MTimeDB(MDB_dbi dbi, MDB_txn* txn)
19 Q_ASSERT(txn !=
nullptr);
27MDB_dbi MTimeDB::create(MDB_txn* txn)
30 int rc = mdb_dbi_open(txn,
"mtimedb", MDB_CREATE | MDB_INTEGERKEY | MDB_DUPSORT | MDB_DUPFIXED | MDB_INTEGERDUP, &dbi);
32 qCWarning(ENGINE) <<
"MTimeDB::create" << mdb_strerror(rc);
39MDB_dbi MTimeDB::open(MDB_txn* txn)
42 int rc = mdb_dbi_open(txn,
"mtimedb", MDB_INTEGERKEY | MDB_DUPSORT | MDB_DUPFIXED | MDB_INTEGERDUP, &dbi);
44 qCWarning(ENGINE) <<
"MTimeDB::open" << mdb_strerror(rc);
51void MTimeDB::put(quint32 mtime, quint64 docId)
54 qCWarning(ENGINE) <<
"MTimeDB::put - docId == 0";
59 key.mv_size =
sizeof(quint32);
60 key.mv_data =
static_cast<void*
>(&mtime);
63 val.mv_size =
sizeof(quint64);
64 val.mv_data =
static_cast<void*
>(&docId);
66 int rc = mdb_put(m_txn, m_dbi, &key, &val, 0);
68 qCWarning(ENGINE) <<
"MTimeDB::put" << mdb_strerror(rc);
75 key.mv_size =
sizeof(quint32);
76 key.mv_data =
static_cast<void*
>(&mtime);
81 mdb_cursor_open(m_txn, m_dbi, &cursor);
83 MDB_val val{0,
nullptr};
84 int rc = mdb_cursor_get(cursor, &key, &val, MDB_SET);
86 if (rc != MDB_NOTFOUND) {
87 qCWarning(ENGINE) <<
"MTimeDB::get" << mtime << mdb_strerror(rc);
89 mdb_cursor_close(cursor);
93 values << *static_cast<quint64*>(val.mv_data);
96 rc = mdb_cursor_get(cursor, &key, &val, MDB_NEXT_DUP);
98 if (rc != MDB_NOTFOUND) {
99 qCWarning(ENGINE) <<
"MTimeDB::get (loop)" << mtime << mdb_strerror(rc);
103 values << *static_cast<quint64*>(val.mv_data);
106 mdb_cursor_close(cursor);
107 std::sort(values.
begin(), values.
end());
112void MTimeDB::del(quint32 mtime, quint64 docId)
115 key.mv_size =
sizeof(quint32);
116 key.mv_data =
static_cast<void*
>(&mtime);
119 val.mv_size =
sizeof(quint64);
120 val.mv_data =
static_cast<void*
>(&docId);
122 int rc = mdb_del(m_txn, m_dbi, &key, &val);
123 if (rc != 0 && rc != MDB_NOTFOUND) {
124 qCWarning(ENGINE) <<
"MTimeDB::del" << mtime << docId << mdb_strerror(rc);
133 if (endTime < beginTime) {
138 key.mv_size =
sizeof(quint32);
139 key.mv_data = &beginTime;
142 mdb_cursor_open(m_txn, m_dbi, &cursor);
144 MDB_val val{0,
nullptr};
145 int rc = mdb_cursor_get(cursor, &key, &val, MDB_SET_RANGE);
147 if (rc != MDB_NOTFOUND) {
148 qCWarning(ENGINE) <<
"MTimeDB::iterRange" << beginTime << endTime << mdb_strerror(rc);
150 mdb_cursor_close(cursor);
157 quint32 time = *
static_cast<quint32*
>(key.mv_data);
158 if (time > endTime) {
161 results << *static_cast<quint64*>(val.mv_data);
163 rc = mdb_cursor_get(cursor, &key, &val, MDB_NEXT);
165 if (rc != MDB_NOTFOUND) {
166 qCWarning(ENGINE) <<
"MTimeDB::iterRange (loop)" << beginTime << endTime << mdb_strerror(rc);
172 mdb_cursor_close(cursor);
177 std::sort(results.
begin(), results.
end());
179 return new VectorPostingIterator(results);
185 mdb_cursor_open(m_txn, m_dbi, &cursor);
187 MDB_val key = {0,
nullptr};
192 int rc = mdb_cursor_get(cursor, &key, &val, MDB_NEXT);
194 qCDebug(ENGINE) <<
"MTimeDB::toTestMap" << mdb_strerror(rc);
198 const quint32 time = *(
static_cast<quint32*
>(key.mv_data));
199 const quint64
id = *(
static_cast<quint64*
>(val.mv_data));
200 map.insert(time,
id);
203 mdb_cursor_close(cursor);
PostingIterator * iterRange(quint32 beginTime, quint32 endTime)
Get documents with an mtime between beginTime and endTime (inclusive)
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:
iterator erase(const_iterator begin, const_iterator end)
bool isEmpty() const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)