Akonadi Search

xapiandatabase.h
1 /*
2  * SPDX-FileCopyrightText: 2014 Vishesh Handa <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 
8 #pragma once
9 
10 #include "search_xapian_export.h"
11 #include <xapian.h>
12 
13 #include <QList>
14 #include <QPair>
15 #include <QString>
16 
17 namespace Akonadi
18 {
19 namespace Search
20 {
21 class XapianDocument;
22 
23 /** Xapian database. */
24 class AKONADI_SEARCH_XAPIAN_EXPORT XapianDatabase
25 {
26 public:
27  /**
28  * Create the Xapian db at path \p path. The parameter \p
29  * writeOnly locks the database as long as this object is
30  * valid
31  */
32  explicit XapianDatabase(const QString &path, bool writeOnly = false);
33  ~XapianDatabase();
34 
35  void replaceDocument(uint id, const Xapian::Document &doc);
36  void replaceDocument(uint id, const XapianDocument &doc);
37  void deleteDocument(uint id);
38 
39  /**
40  * Commit all the pending changes. This may not commit
41  * at this instance as the db might be locked by another process
42  * It emits the committed signal on completion
43  */
44  void commit();
45 
46  XapianDocument document(uint id);
47 
48  /**
49  * A pointer to the actual db. Only use this when doing queries
50  */
51  Xapian::Database *db()
52  {
53  if (m_db) {
54  m_db->reopen();
55  return m_db;
56  }
57  return &m_wDb;
58  }
59 
60  /**
61  * Returns true if the XapianDatabase has changes which need to
62  * be committed
63  */
64  [[nodiscard]] bool haveChanges() const;
65 
66 private:
67  Xapian::Database *m_db = nullptr;
68  Xapian::WritableDatabase m_wDb;
69 
71  QList<DocIdPair> m_docsToAdd;
72  QList<uint> m_docsToRemove;
73 
74  std::string m_path;
75  const bool m_writeOnly = false;
76 
77  Xapian::WritableDatabase createWritableDb();
78 };
79 }
80 }
This class is just a light wrapper over Xapian::Document which provides nice Qt apis.
Xapian::Database * db()
A pointer to the actual db.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Nov 29 2023 04:08:49 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.