File indexing completed on 2024-04-28 15:17:38
0001 /* 0002 This file is part of the KDE Baloo Project 0003 SPDX-FileCopyrightText: 2015 Pinak Ahuja <pinak.ahuja@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #include "unindexedfileindexer.h" 0009 0010 #include "unindexedfileiterator.h" 0011 #include "transaction.h" 0012 #include "fileindexerconfig.h" 0013 #include "baloodebug.h" 0014 #include "basicindexingjob.h" 0015 0016 using namespace Baloo; 0017 0018 UnindexedFileIndexer::UnindexedFileIndexer(Database* db, const FileIndexerConfig* config) 0019 : m_db(db) 0020 , m_config(config) 0021 { 0022 } 0023 0024 void UnindexedFileIndexer::run() 0025 { 0026 const QStringList includeFolders = m_config->includeFolders(); 0027 const BasicIndexingJob::IndexingLevel level = m_config->onlyBasicIndexing() ? 0028 BasicIndexingJob::NoLevel : BasicIndexingJob::MarkForContentIndexing; 0029 0030 for (const QString& includeFolder : includeFolders) { 0031 Transaction tr(m_db, Transaction::ReadWrite); 0032 int transactionDocumentCount = 0; 0033 0034 UnIndexedFileIterator it(m_config, &tr, includeFolder); 0035 while (!it.next().isEmpty()) { 0036 BasicIndexingJob job(it.filePath(), it.mimetype(), level); 0037 if (!job.index()) { 0038 continue; 0039 } 0040 0041 if (it.mTimeChanged() && level == BasicIndexingJob::MarkForContentIndexing) { 0042 job.document().setContentIndexing(true); 0043 } 0044 0045 // We handle modified files by simply updating the mTime and filename in the Db and marking them for ContentIndexing 0046 const quint64 id = job.document().id(); 0047 if (tr.hasDocument(id)) { 0048 DocumentOperations ops = DocumentTime; 0049 if (it.cTimeChanged()) { 0050 ops |= XAttrTerms; 0051 if (QFile::decodeName(tr.documentUrl(id)) != it.filePath()) { 0052 ops |= (FileNameTerms | DocumentUrl); 0053 } 0054 } 0055 tr.replaceDocument(job.document(), ops); 0056 0057 } else { // New file 0058 tr.addDocument(job.document()); 0059 } 0060 0061 transactionDocumentCount++; 0062 if (transactionDocumentCount > 20000) { 0063 qCDebug(BALOO) << "Commit"; 0064 tr.commit(); 0065 tr.reset(Transaction::ReadWrite); 0066 transactionDocumentCount = 0; 0067 } 0068 } 0069 tr.commit(); 0070 } 0071 0072 Q_EMIT done(); 0073 } 0074 0075 #include "moc_unindexedfileindexer.cpp"