ukui-search/libsearch/index/index-generator.h

95 lines
3.1 KiB
C
Raw Normal View History

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>
//#include <QtConcurrent/QtConcurrent>
2020-12-30 15:31:36 +08:00
#include <QStringList>
#include <QMap>
#include <QCryptographicHash>
#include <QMutex>
#include <QQueue>
//#include <QMetaObject>
#include "construct-document.h"
#include "index-status-recorder.h"
2020-12-30 15:31:36 +08:00
#include "document.h"
#include "file-reader.h"
#include "common.h"
#include "pending-file.h"
namespace Zeeker {
//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 {
friend class ConstructDocumentForPath;
friend class ConstructDocumentForContent;
2020-12-30 15:31:36 +08:00
Q_OBJECT
public:
2021-04-26 15:06:47 +08:00
static IndexGenerator *getInstance(bool rebuild = false, QObject *parent = nullptr);
~IndexGenerator();
2020-12-30 15:31:36 +08:00
bool setIndexdataPath();
bool isIndexdataExist();
// Q_INVOKABLE void appendDocListPath(Document doc);
//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:
bool creatAllIndex(QQueue<QVector<QString>> *messageList);
bool creatAllIndex(QQueue<QString> *messageList);
2020-12-30 15:31:36 +08:00
bool deleteAllIndex(QStringList *pathlist);
bool updateIndex(QVector<PendingFile> *pendingFiles);
2020-12-30 15:31:36 +08:00
private:
2021-04-26 15:06:47 +08:00
explicit IndexGenerator(bool rebuild = false, QObject *parent = nullptr);
static QMutex m_mutex;
2020-12-30 15:31:36 +08:00
//For file name index
void HandlePathList(QQueue<QVector<QString> > *messageList);
2020-12-30 15:31:36 +08:00
//For file content index
void HandlePathList(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
void insertIntoDatabase(Document& doc);
void insertIntoContentDatabase(Document& doc);
2020-12-30 15:31:36 +08:00
static QVector<Document> _doc_list_path;
static QMutex _mutex_doc_list_path;
static QVector<Document> _doc_list_content;
static QMutex _mutex_doc_list_content;
2021-04-26 15:06:47 +08:00
QMap<QString, QStringList> m_index_map;
QString m_index_data_path;
Xapian::WritableDatabase* m_database_path;
Xapian::WritableDatabase* m_database_content;
2020-12-30 15:31:36 +08:00
std::string m_docstr;
std::string m_index_text_str;
Xapian::TermGenerator m_indexer;
2020-12-30 15:31:36 +08:00
};
}
2020-12-30 15:31:36 +08:00
#endif // INDEXGENERATOR_H