summaryrefslogtreecommitdiffstats
path: root/common/fulltextindex.h
blob: f24af3bd951f87f5acd32db6b04ffa7e5ee2f566 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once

#include "sink_export.h"

#include <string>
#include <functional>
#include <QString>
#include <memory>
#include "storage.h"
#include "log.h"

namespace Xapian {
    class Database;
    class WritableDatabase;
};

class SINK_EXPORT FulltextIndex
{
public:
    FulltextIndex(const QByteArray &resourceInstanceIdentifier, Sink::Storage::DataStore::AccessMode mode = Sink::Storage::DataStore::ReadOnly);
    ~FulltextIndex();

    void add(const QByteArray &key, const QString &value);
    void add(const QByteArray &key, const QList<QPair<QString, QString>> &values);
    void remove(const QByteArray &key);

    void commitTransaction();
    void abortTransaction();

    QVector<QByteArray> lookup(const QString &key);

    qint64 getDoccount() const;
    struct Result {
        bool found{false};
        QStringList terms;
    };
    Result getIndexContent(const QByteArray &identifier) const;

private:
    Xapian::WritableDatabase* writableDatabase();
    Q_DISABLE_COPY(FulltextIndex);
    Xapian::Database *mDb{nullptr};
    QString mName;
    QString mDbPath;
    bool mHasTransactionOpen{false};
};