File indexing completed on 2024-05-12 05:25:59
0001 #pragma once 0002 0003 #include "sink_export.h" 0004 0005 #include <string> 0006 #include <functional> 0007 #include <QString> 0008 #include <QDateTime> 0009 #include <memory> 0010 #include "storage.h" 0011 #include "log.h" 0012 0013 namespace Xapian { 0014 class Database; 0015 class WritableDatabase; 0016 }; 0017 0018 class SINK_EXPORT FulltextIndex 0019 { 0020 public: 0021 FulltextIndex(const QByteArray &resourceInstanceIdentifier, Sink::Storage::DataStore::AccessMode mode = Sink::Storage::DataStore::ReadOnly); 0022 ~FulltextIndex(); 0023 0024 static bool exists(const QByteArray &resourceInstanceIdentifier); 0025 0026 void add(const Sink::Storage::Identifier &key, const QString &value, const QDateTime &date = {}); 0027 void add(const Sink::Storage::Identifier &key, const QList<QPair<QString, QString>> &values, const QDateTime &date = {}); 0028 void remove(const Sink::Storage::Identifier &key); 0029 0030 void commitTransaction(); 0031 void abortTransaction(); 0032 0033 QVector<Sink::Storage::Identifier> lookup(const QString &key, const Sink::Storage::Identifier &id = {}); 0034 0035 qint64 getDoccount() const; 0036 struct Result { 0037 bool found{false}; 0038 QStringList terms; 0039 }; 0040 Result getIndexContent(const Sink::Storage::Identifier &identifier) const; 0041 Result getIndexContent(const QByteArray &identifier) const 0042 { 0043 return getIndexContent(Sink::Storage::Identifier::fromDisplayByteArray(identifier)); 0044 } 0045 0046 private: 0047 Xapian::WritableDatabase* writableDatabase(); 0048 Q_DISABLE_COPY(FulltextIndex); 0049 Xapian::Database *mDb{nullptr}; 0050 QString mName; 0051 QString mDbPath; 0052 bool mHasTransactionOpen{false}; 0053 };