File indexing completed on 2024-04-28 15:17:31
0001 /* 0002 This file is part of the KDE Baloo project. 0003 SPDX-FileCopyrightText: 2015 Vishesh Handa <me@vhanda.in> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #ifndef BALOO_POSTINGDB_H 0009 #define BALOO_POSTINGDB_H 0010 0011 #include "postingiterator.h" 0012 0013 #include <QByteArray> 0014 #include <QVector> 0015 #include <QRegularExpression> 0016 0017 #include <lmdb.h> 0018 0019 namespace Baloo { 0020 0021 typedef QVector<quint64> PostingList; 0022 0023 /** 0024 * The PostingDB is the main database that maps <term> -> <id1> <id2> <id2> ... 0025 * This is used to lookup ids when searching for a <term>. 0026 */ 0027 class BALOO_ENGINE_EXPORT PostingDB 0028 { 0029 public: 0030 PostingDB(MDB_dbi, MDB_txn* txn); 0031 ~PostingDB(); 0032 0033 static MDB_dbi create(MDB_txn* txn); 0034 static MDB_dbi open(MDB_txn* txn); 0035 0036 void put(const QByteArray& term, const PostingList& list); 0037 PostingList get(const QByteArray& term); 0038 void del(const QByteArray& term); 0039 0040 PostingIterator* iter(const QByteArray& term); 0041 PostingIterator* prefixIter(const QByteArray& term); 0042 PostingIterator* regexpIter(const QRegularExpression& regexp, const QByteArray& prefix); 0043 0044 enum Comparator { 0045 LessEqual, 0046 GreaterEqual, 0047 }; 0048 // For integral types only: 0049 template<typename T> 0050 typename std::enable_if<std::is_integral<T>::value, PostingIterator*>::type 0051 compIter(const QByteArray& prefix, T val, Comparator com) { 0052 qlonglong l = val; 0053 return compIter(prefix, l, com); 0054 } 0055 PostingIterator* compIter(const QByteArray& prefix, qlonglong val, Comparator com); 0056 PostingIterator* compIter(const QByteArray& prefix, double val, Comparator com); 0057 PostingIterator* compIter(const QByteArray& prefix, const QByteArray& val, Comparator com); 0058 0059 QVector<QByteArray> fetchTermsStartingWith(const QByteArray& term); 0060 0061 QMap<QByteArray, PostingList> toTestMap() const; 0062 private: 0063 template <typename Validator> 0064 PostingIterator* iter(const QByteArray& prefix, Validator validate); 0065 0066 MDB_txn* m_txn; 0067 MDB_dbi m_dbi; 0068 }; 0069 0070 } 0071 0072 #endif // BALOO_POSTINGDB_H