| 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 "indexer.h" |
| 9 | #include "basicindexingjob.h" |
| 10 | #include "database.h" |
| 11 | #include "./extractor/result.h" |
| 12 | |
| 13 | #include <KFileMetaData/Extractor> |
| 14 | #include <KFileMetaData/PropertyInfo> |
| 15 | |
| 16 | using namespace Baloo; |
| 17 | |
| 18 | Indexer::Indexer(const QString& url, Transaction* tr) |
| 19 | : m_url(url) |
| 20 | , m_tr(tr) |
| 21 | { |
| 22 | } |
| 23 | |
| 24 | void Indexer::index() |
| 25 | { |
| 26 | const QString mimetype = m_mimeDB.mimeTypeForFile(fileName: m_url).name(); |
| 27 | BasicIndexingJob basicIJ(m_url, mimetype, BasicIndexingJob::NoLevel); |
| 28 | basicIJ.index(); |
| 29 | Baloo::Document doc = basicIJ.document(); |
| 30 | |
| 31 | Result result(m_url, mimetype, KFileMetaData::ExtractionResult::ExtractMetaData | KFileMetaData::ExtractionResult::ExtractPlainText); |
| 32 | result.setDocument(doc); |
| 33 | |
| 34 | const QList<KFileMetaData::Extractor*> exList = m_extractorCollection.fetchExtractors(mimetype); |
| 35 | |
| 36 | for (KFileMetaData::Extractor* ex : exList) { |
| 37 | ex->extract(result: &result); |
| 38 | } |
| 39 | |
| 40 | result.finish(); |
| 41 | if (m_tr->hasDocument(id: doc.id())) { |
| 42 | m_tr->replaceDocument(doc, operations: Everything); |
| 43 | } else { |
| 44 | m_tr->addDocument(doc: result.document()); |
| 45 | } |
| 46 | } |
| 47 |
