Akonadi Search

xapiansearchstore.h
1/*
2 * This file is part of the KDE Akonadi Search Project
3 * SPDX-FileCopyrightText: 2013 Vishesh Handa <me@vhanda.in>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 *
7 */
8
9#pragma once
10
11#include <xapian.h>
12
13#include "core/searchstore.h"
14#include "core/term.h"
15#include "search_xapian_export.h"
16
17#include <QMutexLocker>
18
19namespace Akonadi
20{
21namespace Search
22{
23/**
24 * Implements a search store using Xapian
25 */
26class AKONADI_SEARCH_XAPIAN_EXPORT XapianSearchStore : public SearchStore
27{
28 Q_OBJECT
29public:
30 explicit XapianSearchStore(QObject *parent = nullptr);
31 ~XapianSearchStore() override;
32
33 [[nodiscard]] int exec(const Query &query) override;
34 void close(int queryId) override;
35 bool next(int queryId) override;
36
37 [[nodiscard]] QByteArray id(int queryId) override;
38 [[nodiscard]] QUrl url(int queryId) override;
39
40 /**
41 * Set the path of the xapian database
42 */
43 virtual void setDbPath(const QString &path);
44 [[nodiscard]] virtual QString dbPath();
45
46protected:
47 /**
48 * The derived class should implement the logic for constructing the appropriate
49 * Xapian::Query class from the given values.
50 */
51 virtual Xapian::Query constructQuery(const QString &property, const QVariant &value, Term::Comparator com) = 0;
52
53 virtual Xapian::Query constructFilterQuery(int year, int month, int day);
54
55 /**
56 * Apply any final touches to the query
57 */
58 virtual Xapian::Query finalizeQuery(const Xapian::Query &query);
59
60 /**
61 * Create a query for any custom options.
62 */
63 virtual Xapian::Query applyCustomOptions(const Xapian::Query &q, const QVariantMap &options);
64
65 /**
66 * Returns the url for the document with id \p docid.
67 */
68 virtual QUrl constructUrl(const Xapian::docid &docid) = 0;
69
70 /**
71 * Gives a list of types which have been provided with the query.
72 * This must return the appropriate query which will be ANDed with
73 * the final query
74 */
75 virtual Xapian::Query convertTypes(const QStringList &types) = 0;
76
77 /**
78 * The prefix that should be used when converting an integer
79 * id to a byte array
80 */
81 virtual QByteArray idPrefix() = 0;
82
83 Xapian::Document docForQuery(int queryId);
84
85 /**
86 * Convenience function to AND two Xapian queries together.
87 */
88 Xapian::Query andQuery(const Xapian::Query &a, const Xapian::Query &b);
89
90 Xapian::Database *xapianDb();
91
92protected:
93 QRecursiveMutex m_mutex;
94
95private:
96 [[nodiscard]] AKONADI_SEARCH_XAPIAN_NO_EXPORT Xapian::Query toXapianQuery(const Term &term);
97 [[nodiscard]] AKONADI_SEARCH_XAPIAN_NO_EXPORT Xapian::Query toXapianQuery(Xapian::Query::op op, const QList<Term> &terms);
98
99 [[nodiscard]] AKONADI_SEARCH_XAPIAN_NO_EXPORT Xapian::Query constructSearchQuery(const QString &str);
100
101 struct Result {
102 Xapian::MSet mset;
103 Xapian::MSetIterator it;
104
105 uint lastId;
106 QUrl lastUrl;
107 };
108
109 QHash<int, Result> m_queryMap;
110 int m_nextId = 1;
111
112 QString m_dbPath;
113
114 Xapian::Database *m_db = nullptr;
115};
116}
117}
Search term.
Definition term.h:27
Implements a search store using Xapian.
virtual QUrl constructUrl(const Xapian::docid &docid)=0
Returns the url for the document with id docid.
virtual Xapian::Query convertTypes(const QStringList &types)=0
Gives a list of types which have been provided with the query.
virtual QByteArray idPrefix()=0
The prefix that should be used when converting an integer id to a byte array.
virtual Xapian::Query constructQuery(const QString &property, const QVariant &value, Term::Comparator com)=0
The derived class should implement the logic for constructing the appropriate Xapian::Query class fro...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.