File indexing completed on 2024-04-21 03:51:39
0001 /* 0002 This file is part of the KDE Baloo project. 0003 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #ifndef BALOO_DOCUMENT_H 0009 #define BALOO_DOCUMENT_H 0010 0011 #include "engine_export.h" 0012 #include <QByteArray> 0013 #include <QDebug> 0014 #include <QVector> 0015 0016 namespace Baloo { 0017 0018 class WriteTransaction; 0019 class TermGeneratorTest; 0020 0021 /** 0022 * A document represents an indexed file to be stored in the Baloo engine. 0023 * 0024 * It is a large collection of words along with their respective positions. 0025 * One typically never needs to have all of this in memory except when creating the 0026 * Document for indexing. 0027 * 0028 * This is why Documents can be created and saved into the database, but not fetched. 0029 */ 0030 class BALOO_ENGINE_EXPORT Document 0031 { 0032 public: 0033 Document(); 0034 0035 void addTerm(const QByteArray& term); 0036 void addPositionTerm(const QByteArray& term, int position = 0); 0037 0038 void addXattrTerm(const QByteArray& term); 0039 void addXattrPositionTerm(const QByteArray& term, int position = 0); 0040 0041 void addFileNameTerm(const QByteArray& term); 0042 void addFileNamePositionTerm(const QByteArray& term, int position = 0); 0043 0044 quint64 id() const; 0045 void setId(quint64 id); 0046 quint64 parentId() const; 0047 void setParentId(quint64 parentId); 0048 0049 QByteArray url() const; 0050 void setUrl(const QByteArray& url); 0051 0052 /** 0053 * This flag is used to signify if the file needs its contents to be indexed. 0054 * It defaults to false 0055 */ 0056 void setContentIndexing(bool val); 0057 bool contentIndexing() const; 0058 0059 void setMTime(quint32 val) { m_mTime = val; } 0060 void setCTime(quint32 val) { m_cTime = val; } 0061 0062 void setData(const QByteArray& data); 0063 0064 private: 0065 quint64 m_id = 0; 0066 quint64 m_parentId = 0; 0067 0068 struct TermData { 0069 QVector<uint> positions; 0070 }; 0071 QMap<QByteArray, TermData> m_terms; 0072 QMap<QByteArray, TermData> m_xattrTerms; 0073 QMap<QByteArray, TermData> m_fileNameTerms; 0074 0075 QByteArray m_url; 0076 bool m_contentIndexing = false; 0077 0078 quint32 m_mTime = 0; //< modification time, seconds since Epoch 0079 quint32 m_cTime = 0; //< inode change time, seconds since Epoch 0080 QByteArray m_data; 0081 0082 friend class WriteTransaction; 0083 friend class TermGeneratorTest; 0084 friend class BasicIndexingJobTest; 0085 }; 0086 0087 inline QDebug operator<<(QDebug dbg, const Document &doc) { 0088 dbg << doc.id() << doc.url(); 0089 return dbg; 0090 } 0091 0092 } 0093 0094 #endif // BALOO_DOCUMENT_H