1 | /* |
2 | This file is part of the KDE Baloo project. |
3 | SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.1-or-later |
6 | */ |
7 | |
8 | #ifndef BALOO_DOCUMENT_H |
9 | #define BALOO_DOCUMENT_H |
10 | |
11 | #include "engine_export.h" |
12 | #include <QByteArray> |
13 | #include <QDebug> |
14 | #include <QVector> |
15 | |
16 | namespace Baloo { |
17 | |
18 | class WriteTransaction; |
19 | class TermGeneratorTest; |
20 | |
21 | /** |
22 | * A document represents an indexed file to be stored in the Baloo engine. |
23 | * |
24 | * It is a large collection of words along with their respective positions. |
25 | * One typically never needs to have all of this in memory except when creating the |
26 | * Document for indexing. |
27 | * |
28 | * This is why Documents can be created and saved into the database, but not fetched. |
29 | */ |
30 | class BALOO_ENGINE_EXPORT Document |
31 | { |
32 | public: |
33 | Document(); |
34 | |
35 | void addTerm(const QByteArray& term); |
36 | void addPositionTerm(const QByteArray& term, int position = 0); |
37 | |
38 | void addXattrTerm(const QByteArray& term); |
39 | void addXattrPositionTerm(const QByteArray& term, int position = 0); |
40 | |
41 | void addFileNameTerm(const QByteArray& term); |
42 | void addFileNamePositionTerm(const QByteArray& term, int position = 0); |
43 | |
44 | quint64 id() const; |
45 | void setId(quint64 id); |
46 | quint64 parentId() const; |
47 | void setParentId(quint64 parentId); |
48 | |
49 | QByteArray url() const; |
50 | void setUrl(const QByteArray& url); |
51 | |
52 | /** |
53 | * This flag is used to signify if the file needs its contents to be indexed. |
54 | * It defaults to false |
55 | */ |
56 | void setContentIndexing(bool val); |
57 | bool contentIndexing() const; |
58 | |
59 | void setMTime(quint32 val) { m_mTime = val; } |
60 | void setCTime(quint32 val) { m_cTime = val; } |
61 | |
62 | void setData(const QByteArray& data); |
63 | |
64 | private: |
65 | quint64 m_id = 0; |
66 | quint64 m_parentId = 0; |
67 | |
68 | struct TermData { |
69 | QVector<uint> positions; |
70 | }; |
71 | QMap<QByteArray, TermData> m_terms; |
72 | QMap<QByteArray, TermData> m_xattrTerms; |
73 | QMap<QByteArray, TermData> m_fileNameTerms; |
74 | |
75 | QByteArray m_url; |
76 | bool m_contentIndexing = false; |
77 | |
78 | quint32 m_mTime = 0; //< modification time, seconds since Epoch |
79 | quint32 m_cTime = 0; //< inode change time, seconds since Epoch |
80 | QByteArray m_data; |
81 | |
82 | friend class WriteTransaction; |
83 | friend class TermGeneratorTest; |
84 | friend class BasicIndexingJobTest; |
85 | }; |
86 | |
87 | inline QDebug operator<<(QDebug dbg, const Document &doc) { |
88 | dbg << doc.id() << doc.url(); |
89 | return dbg; |
90 | } |
91 | |
92 | } |
93 | |
94 | #endif // BALOO_DOCUMENT_H |
95 | |