File indexing completed on 2024-05-12 05:11:21

0001 /*
0002  * SPDX-FileCopyrightText: 2014 Vishesh Handa <me@vhanda.in>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  *
0006  */
0007 
0008 #pragma once
0009 
0010 #include <QString>
0011 #include <xapian.h>
0012 
0013 #include "search_xapian_export.h"
0014 #include "xapiantermgenerator.h"
0015 
0016 namespace Akonadi
0017 {
0018 namespace Search
0019 {
0020 /**
0021  * This class is just a light wrapper over Xapian::Document
0022  * which provides nice Qt apis.
0023  */
0024 class AKONADI_SEARCH_XAPIAN_EXPORT XapianDocument
0025 {
0026 public:
0027     XapianDocument();
0028     XapianDocument(const Xapian::Document &doc);
0029 
0030     void addTerm(const QString &term, const QString &prefix = QString());
0031     void addBoolTerm(const QString &term, const QString &prefix = QString());
0032     void addBoolTerm(int term, const QString &prefix);
0033 
0034     void indexText(const QString &text, int wdfInc = 1);
0035     void indexText(const QString &text, const QString &prefix, int wdfInc = 1);
0036 
0037     void addValue(int pos, const QString &value);
0038 
0039     Xapian::Document doc() const;
0040 
0041     QString fetchTermStartsWith(const QByteArray &term);
0042 
0043     /**
0044      * Remove all the terms which start with the prefix \p prefix
0045      *
0046      * \return true if the document was modified
0047      */
0048     bool removeTermStartsWith(const QByteArray &prefix);
0049 
0050 private:
0051     Xapian::Document m_doc;
0052     XapianTermGenerator m_termGen;
0053 };
0054 }
0055 }