| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the Qt Assistant of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QHELPSEARCHINDEXREADERDEFAULT_H
|
|---|
| 43 | #define QHELPSEARCHINDEXREADERDEFAULT_H
|
|---|
| 44 |
|
|---|
| 45 | //
|
|---|
| 46 | // W A R N I N G
|
|---|
| 47 | // -------------
|
|---|
| 48 | //
|
|---|
| 49 | // This file is not part of the Qt API. It exists for the convenience
|
|---|
| 50 | // of the help generator tools. This header file may change from version
|
|---|
| 51 | // to version without notice, or even be removed.
|
|---|
| 52 | //
|
|---|
| 53 | // We mean it.
|
|---|
| 54 | //
|
|---|
| 55 |
|
|---|
| 56 | #include "qhelpsearchindex_default_p.h"
|
|---|
| 57 | #include "qhelpsearchengine.h"
|
|---|
| 58 |
|
|---|
| 59 | #include <QtCore/QHash>
|
|---|
| 60 | #include <QtCore/QPair>
|
|---|
| 61 | #include <QtCore/QList>
|
|---|
| 62 | #include <QtCore/QMutex>
|
|---|
| 63 | #include <QtCore/QString>
|
|---|
| 64 | #include <QtCore/QThread>
|
|---|
| 65 | #include <QtCore/QObject>
|
|---|
| 66 | #include <QtCore/QVector>
|
|---|
| 67 | #include <QtCore/QByteArray>
|
|---|
| 68 | #include <QtCore/QStringList>
|
|---|
| 69 | #include <QtCore/QWaitCondition>
|
|---|
| 70 |
|
|---|
| 71 | QT_BEGIN_NAMESPACE
|
|---|
| 72 |
|
|---|
| 73 | struct Entry;
|
|---|
| 74 | struct PosEntry;
|
|---|
| 75 |
|
|---|
| 76 | namespace qt {
|
|---|
| 77 | namespace fulltextsearch {
|
|---|
| 78 | namespace std {
|
|---|
| 79 |
|
|---|
| 80 | class Reader
|
|---|
| 81 | {
|
|---|
| 82 | typedef QList<QStringList> DocumentList;
|
|---|
| 83 | typedef QHash<QString, Entry*> EntryTable;
|
|---|
| 84 | typedef QPair<EntryTable, DocumentList> Index;
|
|---|
| 85 | typedef QHash<QString, Index> IndexTable;
|
|---|
| 86 |
|
|---|
| 87 | public:
|
|---|
| 88 | Reader();
|
|---|
| 89 | ~Reader();
|
|---|
| 90 |
|
|---|
| 91 | bool readIndex();
|
|---|
| 92 | bool initCheck() const;
|
|---|
| 93 | void setIndexPath(const QString &path);
|
|---|
| 94 | void filterFilesForAttributes(const QStringList &attributes);
|
|---|
| 95 | void setIndexFile(const QString &namespaceName, const QString &attributes);
|
|---|
| 96 | bool splitSearchTerm(const QString &searchTerm, QStringList *terms,
|
|---|
| 97 | QStringList *termSeq, QStringList *seqWords);
|
|---|
| 98 |
|
|---|
| 99 | void searchInIndex(const QStringList &terms);
|
|---|
| 100 | QVector<DocumentInfo> hits();
|
|---|
| 101 | bool searchForPattern(const QStringList &patterns,
|
|---|
| 102 | const QStringList &words, const QByteArray &data);
|
|---|
| 103 |
|
|---|
| 104 | private:
|
|---|
| 105 | QVector<Document> setupDummyTerm(const QStringList &terms, const EntryTable &entryTable);
|
|---|
| 106 | QStringList getWildcardTerms(const QString &term, const EntryTable &entryTable);
|
|---|
| 107 | void buildMiniIndex(const QString &string);
|
|---|
| 108 | void reset();
|
|---|
| 109 | void cleanupIndex(EntryTable &entryTable);
|
|---|
| 110 |
|
|---|
| 111 | private:
|
|---|
| 112 | uint wordNum;
|
|---|
| 113 | QString indexPath;
|
|---|
| 114 | QString indexFile;
|
|---|
| 115 | QString documentFile;
|
|---|
| 116 |
|
|---|
| 117 | IndexTable indexTable;
|
|---|
| 118 | QList<TermInfo> termList;
|
|---|
| 119 | IndexTable searchIndexTable;
|
|---|
| 120 | QHash<QString, PosEntry*> miniIndex;
|
|---|
| 121 | };
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 | class QHelpSearchIndexReader : public QThread
|
|---|
| 125 | {
|
|---|
| 126 | Q_OBJECT
|
|---|
| 127 |
|
|---|
| 128 | public:
|
|---|
| 129 | QHelpSearchIndexReader();
|
|---|
| 130 | ~QHelpSearchIndexReader();
|
|---|
| 131 |
|
|---|
| 132 | void cancelSearching();
|
|---|
| 133 | void search(const QString &collectionFile,
|
|---|
| 134 | const QString &indexFilesFolder,
|
|---|
| 135 | const QList<QHelpSearchQuery> &queryList);
|
|---|
| 136 |
|
|---|
| 137 | int hitsCount() const;
|
|---|
| 138 | QHelpSearchEngine::SearchHit hit(int index) const;
|
|---|
| 139 |
|
|---|
| 140 | signals:
|
|---|
| 141 | void searchingStarted();
|
|---|
| 142 | void searchingFinished(int hits);
|
|---|
| 143 |
|
|---|
| 144 | private:
|
|---|
| 145 | void run();
|
|---|
| 146 |
|
|---|
| 147 | private:
|
|---|
| 148 | QMutex mutex;
|
|---|
| 149 | Reader m_reader;
|
|---|
| 150 | QWaitCondition waitCondition;
|
|---|
| 151 | QList<QHelpSearchEngine::SearchHit> hitList;
|
|---|
| 152 |
|
|---|
| 153 | bool m_cancel;
|
|---|
| 154 | QList<QHelpSearchQuery> m_query;
|
|---|
| 155 | QString m_collectionFile;
|
|---|
| 156 | QString m_indexFilesFolder;
|
|---|
| 157 | };
|
|---|
| 158 |
|
|---|
| 159 | } // namespace std
|
|---|
| 160 | } // namespace fulltextsearch
|
|---|
| 161 | } // namespace qt
|
|---|
| 162 |
|
|---|
| 163 | QT_END_NAMESPACE
|
|---|
| 164 |
|
|---|
| 165 | #endif // QHELPSEARCHINDEXREADERDEFAULT_H
|
|---|