Baloo

unindexedfileindexer.cpp
1/*
2 This file is part of the KDE Baloo Project
3 SPDX-FileCopyrightText: 2015 Pinak Ahuja <pinak.ahuja@gmail.com>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include "unindexedfileindexer.h"
9
10#include "unindexedfileiterator.h"
11#include "transaction.h"
12#include "fileindexerconfig.h"
13#include "baloodebug.h"
14#include "basicindexingjob.h"
15
16using namespace Baloo;
17
18UnindexedFileIndexer::UnindexedFileIndexer(Database* db, const FileIndexerConfig* config)
19 : m_db(db)
20 , m_config(config)
21{
22}
23
24void UnindexedFileIndexer::run()
25{
26 const QStringList includeFolders = m_config->includeFolders();
27 const BasicIndexingJob::IndexingLevel level = m_config->onlyBasicIndexing() ?
28 BasicIndexingJob::NoLevel : BasicIndexingJob::MarkForContentIndexing;
29
30 for (const QString& includeFolder : includeFolders) {
31 Transaction tr(m_db, Transaction::ReadWrite);
33
34 UnIndexedFileIterator it(m_config, &tr, includeFolder);
35 while (!it.next().isEmpty()) {
36 BasicIndexingJob job(it.filePath(), it.mimetype(), level);
37 if (!job.index()) {
38 continue;
39 }
40
41 if (it.mTimeChanged() && level == BasicIndexingJob::MarkForContentIndexing) {
42 job.document().setContentIndexing(true);
43 }
44
45 // We handle modified files by simply updating the mTime and filename in the Db and marking them for ContentIndexing
46 const quint64 id = job.document().id();
47 if (tr.hasDocument(id)) {
48 DocumentOperations ops = DocumentTime;
49 if (it.cTimeChanged()) {
50 ops |= XAttrTerms;
51 if (QFile::decodeName(tr.documentUrl(id)) != it.filePath()) {
52 ops |= (FileNameTerms | DocumentUrl);
53 }
54 }
55 tr.replaceDocument(job.document(), ops);
56
57 } else { // New file
58 tr.addDocument(job.document());
59 }
60
62 if (transactionDocumentCount > 20000) {
63 qCDebug(BALOO) << "Commit";
64 tr.commit();
65 tr.reset(Transaction::ReadWrite);
67 }
68 }
69 tr.commit();
70 }
71
72 Q_EMIT done();
73}
74
75#include "moc_unindexedfileindexer.cpp"
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
Iterate over all the files (and directories) under a specific directory which require indexing.
Implements storage for docIds without any associated data Instantiated for:
Definition coding.cpp:11
QStringView level(QStringView ifopt)
QString decodeName(const QByteArray &localFileName)
bool isEmpty() const const
Q_EMITQ_EMIT
QString tr(const char *sourceText, const char *disambiguation, int n)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.