Akonadi Search

xapiandatabase.h
1/*
2 * SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
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
17namespace Akonadi
18{
19namespace Search
20{
21class XapianDocument;
22
23/** Xapian database. */
24class AKONADI_SEARCH_XAPIAN_EXPORT XapianDatabase
25{
26public:
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);
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 [[nodiscard]] 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
66private:
67 Xapian::Database *m_db = nullptr;
68 Xapian::WritableDatabase m_wDb;
69
70 using DocIdPair = QPair<Xapian::docid, Xapian::Document>;
71 QList<DocIdPair> m_docsToAdd;
72 QList<uint> m_docsToRemove;
73
74 std::string m_path;
75 const bool m_writeOnly = false;
76
77 AKONADI_SEARCH_XAPIAN_NO_EXPORT Xapian::WritableDatabase createWritableDb();
78};
79}
80}
Xapian::Database * db()
A pointer to the actual db.
This class is just a light wrapper over Xapian::Document which provides nice Qt apis.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.