File indexing completed on 2024-04-28 03:51:47

0001 /*
0002     This file is part of the KDE Baloo Project
0003     SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #ifndef EXTRACTIONRESULT_H
0009 #define EXTRACTIONRESULT_H
0010 
0011 #include <KFileMetaData/ExtractionResult>
0012 
0013 #include "document.h"
0014 #include "termgenerator.h"
0015 
0016 /**
0017  * \class Result result.h
0018  *
0019  * \brief The result class is where all the data extracted by
0020  * the KFileMetaData extractors is saved to.
0021  * It implements the KFileMetaData::ExtractionResult interface.
0022  * The results can be retrieved as a Baloo::Document using
0023  * \c document() and stored in the database.
0024  *
0025  */
0026 class Result : public KFileMetaData::ExtractionResult
0027 {
0028 public:
0029     Result();
0030     Result(const QString& url, const QString& mimetype, const Flags& flags = ExtractMetaData | ExtractPlainText);
0031 
0032     void add(KFileMetaData::Property::Property property, const QVariant& value) override;
0033     void append(const QString& text) override;
0034     void addType(KFileMetaData::Type::Type type) override;
0035 
0036     /**
0037      * Can be used to add extraction results to an existing
0038      * Baloo::Document. Has to be called before passing the
0039      * Result to KFileMetaData::Extractor::extract().
0040      * \param doc The Baloo::Document
0041      */
0042     void setDocument(const Baloo::Document& doc);
0043 
0044     /**
0045      * Returns the Baloo document to which the results from the extractors
0046      * are saved.
0047      */
0048     Baloo::Document& document() {
0049         return m_doc;
0050     }
0051 
0052     /**
0053      * Applies the finishing touches on the document, and makes
0054      * it ready to be pushed into the db.
0055      */
0056     void finish();
0057 
0058 private:
0059     /**
0060      * The document that represents the file that is to be indexed.
0061      */
0062     Baloo::Document m_doc;
0063     /**
0064      * Contains the position state of the metadata and adds it to the document.
0065      */
0066     Baloo::TermGenerator m_termGen;
0067     /**
0068      * Contains the position state of plain text and adds it to the document.
0069      */
0070     Baloo::TermGenerator m_termGenForText;
0071     /**
0072      * Contains all indexed property data from the extractors.
0073      */
0074     KFileMetaData::PropertyMultiMap m_map;
0075 };
0076 
0077 #endif // EXTRACTIONRESULT_H