Baloo

document.h
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
16namespace Baloo {
17
18class WriteTransaction;
19class 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 */
30class BALOO_ENGINE_EXPORT Document
31{
32public:
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
64private:
65 quint64 m_id = 0;
66 quint64 m_parentId = 0;
67
68 struct TermData {
69 QVector<uint> positions;
70 };
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
87inline 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
A document represents an indexed file to be stored in the Baloo engine.
Definition document.h:31
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.