1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QHELPSEARCHENGINE_H
5#define QHELPSEARCHENGINE_H
6
7#include <QtHelp/qhelp_global.h>
8
9#include <QtCore/QMap>
10#include <QtCore/QUrl>
11#include <QtCore/QObject>
12#include <QtCore/QSharedDataPointer>
13#include <QtCore/QString>
14#include <QtCore/QStringList>
15
16QT_BEGIN_NAMESPACE
17
18class QHelpEngineCore;
19class QHelpSearchQueryWidget;
20class QHelpSearchEnginePrivate;
21class QHelpSearchResultData;
22class QHelpSearchResultWidget;
23
24class QHELP_EXPORT QHelpSearchQuery
25{
26public:
27 enum FieldName { DEFAULT = 0, FUZZY, WITHOUT, PHRASE, ALL, ATLEAST };
28
29 QHelpSearchQuery()
30 : fieldName(DEFAULT) { wordList.clear(); }
31 QHelpSearchQuery(FieldName field, const QStringList &wordList_)
32 : fieldName(field), wordList(wordList_) {}
33
34 FieldName fieldName;
35 QStringList wordList;
36};
37
38class QHELP_EXPORT QHelpSearchResult
39{
40public:
41 QHelpSearchResult();
42 QHelpSearchResult(const QHelpSearchResult &other);
43 QHelpSearchResult(const QUrl &url, const QString &title, const QString &snippet);
44 ~QHelpSearchResult();
45
46 QHelpSearchResult &operator=(const QHelpSearchResult &other);
47
48 QString title() const;
49 QUrl url() const;
50 QString snippet() const;
51
52private:
53 QSharedDataPointer<QHelpSearchResultData> d;
54};
55
56class QHELP_EXPORT QHelpSearchEngine : public QObject
57{
58 Q_OBJECT
59
60public:
61 explicit QHelpSearchEngine(QHelpEngineCore *helpEngine, QObject *parent = nullptr);
62 ~QHelpSearchEngine();
63
64 QHelpSearchQueryWidget* queryWidget();
65 QHelpSearchResultWidget* resultWidget();
66
67#if QT_DEPRECATED_SINCE(5, 9)
68 typedef QPair<QString, QString> SearchHit;
69
70 QT_DEPRECATED int hitsCount() const;
71 QT_DEPRECATED int hitCount() const;
72 QT_DEPRECATED QList<SearchHit> hits(int start, int end) const;
73 QT_DEPRECATED QList<QHelpSearchQuery> query() const;
74#endif
75
76 int searchResultCount() const;
77 QList<QHelpSearchResult> searchResults(int start, int end) const;
78 QString searchInput() const;
79
80public Q_SLOTS:
81 void reindexDocumentation();
82 void cancelIndexing();
83
84#if QT_DEPRECATED_SINCE(5, 9)
85 QT_DEPRECATED void search(const QList<QHelpSearchQuery> &queryList);
86#endif
87
88 void search(const QString &searchInput);
89 void cancelSearching();
90
91 void scheduleIndexDocumentation();
92
93Q_SIGNALS:
94 void indexingStarted();
95 void indexingFinished();
96
97 void searchingStarted();
98 void searchingFinished(int searchResultCount);
99
100private Q_SLOTS:
101 void indexDocumentation();
102
103private:
104 QHelpSearchEnginePrivate *d;
105};
106
107QT_END_NAMESPACE
108
109#endif // QHELPSEARCHENGINE_H
110

source code of qttools/src/assistant/help/qhelpsearchengine.h