Baloo

postingdb.h
1 /*
2  This file is part of the KDE Baloo project.
3  SPDX-FileCopyrightText: 2015 Vishesh Handa <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7 
8 #ifndef BALOO_POSTINGDB_H
9 #define BALOO_POSTINGDB_H
10 
11 #include "postingiterator.h"
12 
13 #include <QByteArray>
14 #include <QVector>
15 #include <QRegularExpression>
16 
17 #include <lmdb.h>
18 
19 namespace Baloo {
20 
21 typedef QVector<quint64> PostingList;
22 
23 /**
24  * The PostingDB is the main database that maps <term> -> <id1> <id2> <id2> ...
25  * This is used to lookup ids when searching for a <term>.
26  */
27 class BALOO_ENGINE_EXPORT PostingDB
28 {
29 public:
30  PostingDB(MDB_dbi, MDB_txn* txn);
31  ~PostingDB();
32 
33  static MDB_dbi create(MDB_txn* txn);
34  static MDB_dbi open(MDB_txn* txn);
35 
36  void put(const QByteArray& term, const PostingList& list);
37  PostingList get(const QByteArray& term);
38  void del(const QByteArray& term);
39 
40  PostingIterator* iter(const QByteArray& term);
41  PostingIterator* prefixIter(const QByteArray& term);
42  PostingIterator* regexpIter(const QRegularExpression& regexp, const QByteArray& prefix);
43 
44  enum Comparator {
45  LessEqual,
46  GreaterEqual,
47  };
48  // For integral types only:
49  template<typename T>
50  typename std::enable_if<std::is_integral<T>::value, PostingIterator*>::type
51  compIter(const QByteArray& prefix, T val, Comparator com) {
52  qlonglong l = val;
53  return compIter(prefix, l, com);
54  }
55  PostingIterator* compIter(const QByteArray& prefix, qlonglong val, Comparator com);
56  PostingIterator* compIter(const QByteArray& prefix, double val, Comparator com);
57  PostingIterator* compIter(const QByteArray& prefix, const QByteArray& val, Comparator com);
58 
59  QVector<QByteArray> fetchTermsStartingWith(const QByteArray& term);
60 
61  QMap<QByteArray, PostingList> toTestMap() const;
62 private:
63  template <typename Validator>
64  PostingIterator* iter(const QByteArray& prefix, Validator validate);
65 
66  MDB_txn* m_txn;
67  MDB_dbi m_dbi;
68 };
69 
70 }
71 
72 #endif // BALOO_POSTINGDB_H
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:
Definition: coding.cpp:11
The PostingDB is the main database that maps -> <id1> <id2> <id2> ...
Definition: postingdb.h:27
virtual bool put(ScriptableExtension *callerPrincipal, quint64 objId, const QString &propName, const QVariant &value)
virtual QVariant get(ScriptableExtension *callerPrincipal, quint64 objId, const QString &propName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 03:56:26 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.