2021-01-29 11:43:07 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Authors: zhangpengfei <zhangpengfei@kylinos.cn>
|
|
|
|
*
|
|
|
|
*/
|
2020-12-30 15:31:36 +08:00
|
|
|
#ifndef INDEXGENERATOR_H
|
|
|
|
#define INDEXGENERATOR_H
|
|
|
|
|
|
|
|
#include <xapian.h>
|
|
|
|
#include <QObject>
|
2021-01-09 11:25:07 +08:00
|
|
|
//#include <QtConcurrent/QtConcurrent>
|
2020-12-30 15:31:36 +08:00
|
|
|
#include <QStringList>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QCryptographicHash>
|
2021-01-10 15:59:17 +08:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QQueue>
|
2021-01-19 10:44:28 +08:00
|
|
|
//#include <QMetaObject>
|
2021-06-10 20:43:57 +08:00
|
|
|
#include "construct-document.h"
|
2021-05-13 11:17:07 +08:00
|
|
|
#include "index-status-recorder.h"
|
2020-12-30 15:31:36 +08:00
|
|
|
#include "document.h"
|
|
|
|
#include "file-reader.h"
|
2021-05-13 11:17:07 +08:00
|
|
|
#include "common.h"
|
2021-06-10 20:43:57 +08:00
|
|
|
#include "pending-file.h"
|
2021-01-19 10:44:28 +08:00
|
|
|
|
2021-12-14 14:43:35 +08:00
|
|
|
namespace UkuiSearch {
|
2021-06-10 20:43:57 +08:00
|
|
|
//extern QVector<Document> *_doc_list_path;
|
|
|
|
//extern QMutex _mutex_doc_list_path;
|
|
|
|
//extern QVector<Document> *_doc_list_content;
|
|
|
|
//extern QMutex _mutex_doc_list_content;
|
2020-12-30 15:31:36 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
class IndexGenerator : public QObject {
|
2021-06-10 20:43:57 +08:00
|
|
|
friend class ConstructDocumentForPath;
|
|
|
|
friend class ConstructDocumentForContent;
|
2022-01-21 16:53:19 +08:00
|
|
|
friend class ConstructDocumentForOcr;
|
2020-12-30 15:31:36 +08:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2022-03-17 15:40:55 +08:00
|
|
|
static IndexGenerator *getInstance();
|
2021-01-10 09:01:22 +08:00
|
|
|
~IndexGenerator();
|
2022-03-17 15:40:55 +08:00
|
|
|
|
|
|
|
void rebuildIndexDatabase(const QString &path = INDEX_PATH);
|
|
|
|
void rebuildContentIndexDatabase(const QString &path = CONTENT_INDEX_PATH);
|
|
|
|
void rebuildOcrIndexDatabase(const QString &path = OCR_INDEX_PATH);
|
2021-01-19 10:44:28 +08:00
|
|
|
// Q_INVOKABLE void appendDocListPath(Document doc);
|
2021-01-07 15:21:53 +08:00
|
|
|
//for search test
|
2020-12-30 15:31:36 +08:00
|
|
|
static QStringList IndexSearch(QString indexText);
|
2021-03-01 09:07:33 +08:00
|
|
|
void setSynonym();
|
2020-12-30 15:31:36 +08:00
|
|
|
Q_SIGNALS:
|
|
|
|
void transactionFinished();
|
|
|
|
void searchFinish();
|
|
|
|
public Q_SLOTS:
|
2021-01-10 15:59:17 +08:00
|
|
|
bool creatAllIndex(QQueue<QVector<QString>> *messageList);
|
|
|
|
bool creatAllIndex(QQueue<QString> *messageList);
|
2022-01-21 16:53:19 +08:00
|
|
|
bool creatOcrIndex(QQueue<QString> *messageList);
|
2020-12-30 15:31:36 +08:00
|
|
|
bool deleteAllIndex(QStringList *pathlist);
|
2021-10-27 15:16:43 +08:00
|
|
|
bool deleteContentIndex(QStringList *pathlist);
|
2022-01-21 16:53:19 +08:00
|
|
|
bool deleteOcrIndex(QStringList *pathlist);
|
2021-06-10 20:43:57 +08:00
|
|
|
bool updateIndex(QVector<PendingFile> *pendingFiles);
|
2020-12-30 15:31:36 +08:00
|
|
|
|
|
|
|
private:
|
2022-03-17 15:40:55 +08:00
|
|
|
explicit IndexGenerator(QObject *parent = nullptr);
|
2021-01-10 15:59:17 +08:00
|
|
|
static QMutex m_mutex;
|
2020-12-30 15:31:36 +08:00
|
|
|
//For file name index
|
2021-01-10 15:59:17 +08:00
|
|
|
void HandlePathList(QQueue<QVector<QString> > *messageList);
|
2020-12-30 15:31:36 +08:00
|
|
|
//For file content index
|
2021-01-10 15:59:17 +08:00
|
|
|
void HandlePathList(QQueue<QString> *messageList);
|
2022-01-21 16:53:19 +08:00
|
|
|
//For ocr index
|
|
|
|
void HandleOcrPathList(QQueue<QString> *messageList);
|
2020-12-30 15:31:36 +08:00
|
|
|
static Document GenerateDocument(const QVector<QString> &list);
|
|
|
|
static Document GenerateContentDocument(const QString &list);
|
|
|
|
//add one data in database
|
2021-01-19 19:26:39 +08:00
|
|
|
void insertIntoDatabase(Document& doc);
|
|
|
|
void insertIntoContentDatabase(Document& doc);
|
2020-12-30 15:31:36 +08:00
|
|
|
|
2021-11-02 15:44:12 +08:00
|
|
|
static QVector<Document> g_docListForPath;
|
|
|
|
static QMutex g_mutexDocListForPath;
|
|
|
|
static QVector<Document> g_docListForContent;
|
|
|
|
static QMutex g_mutexDocListForContent;
|
2022-01-21 16:53:19 +08:00
|
|
|
static QVector<Document> g_docListForOcr;
|
|
|
|
static QMutex g_mutexDocListForOcr;
|
2021-04-26 15:06:47 +08:00
|
|
|
QMap<QString, QStringList> m_index_map;
|
2021-01-19 19:26:39 +08:00
|
|
|
QString m_index_data_path;
|
2022-03-17 15:40:55 +08:00
|
|
|
Xapian::WritableDatabase* m_database_path = nullptr;
|
|
|
|
Xapian::WritableDatabase* m_database_content = nullptr;
|
|
|
|
Xapian::WritableDatabase* m_database_ocr = nullptr;
|
2020-12-30 15:31:36 +08:00
|
|
|
std::string m_docstr;
|
|
|
|
std::string m_index_text_str;
|
2021-01-19 19:26:39 +08:00
|
|
|
Xapian::TermGenerator m_indexer;
|
2020-12-30 15:31:36 +08:00
|
|
|
};
|
2021-04-30 16:28:50 +08:00
|
|
|
}
|
2020-12-30 15:31:36 +08:00
|
|
|
|
|
|
|
#endif // INDEXGENERATOR_H
|