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>
|
2020-12-30 15:31:36 +08:00
|
|
|
#include "document.h"
|
|
|
|
#include "file-reader.h"
|
2021-01-19 10:44:28 +08:00
|
|
|
//#include "chinese-segmentation.h"
|
|
|
|
|
|
|
|
extern QList<Document> *_doc_list_path;
|
|
|
|
extern QMutex _mutex_doc_list_path;
|
|
|
|
extern QList<Document> *_doc_list_content;
|
|
|
|
extern QMutex _mutex_doc_list_content;
|
2020-12-30 15:31:36 +08:00
|
|
|
|
|
|
|
class IndexGenerator : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2021-01-19 10:44:28 +08:00
|
|
|
static IndexGenerator *getInstance(bool rebuild = false,QObject *parent = nullptr);
|
2021-01-10 09:01:22 +08:00
|
|
|
~IndexGenerator();
|
2020-12-30 15:31:36 +08:00
|
|
|
bool setIndexdataPath();
|
|
|
|
bool isIndexdataExist();
|
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);
|
|
|
|
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);
|
2020-12-30 15:31:36 +08:00
|
|
|
bool deleteAllIndex(QStringList *pathlist);
|
|
|
|
|
|
|
|
private:
|
2021-01-06 17:42:35 +08:00
|
|
|
explicit IndexGenerator(bool rebuild = false,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);
|
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);
|
2020-12-31 21:14:13 +08:00
|
|
|
void insertIntoContentDatabase(Document doc);
|
2020-12-30 15:31:36 +08:00
|
|
|
|
|
|
|
QMap<QString,QStringList> *m_index_map;
|
2021-01-19 10:44:28 +08:00
|
|
|
// QList<Document> *m_doc_list_path; //for path index
|
|
|
|
// QList<Document> *m_doc_list_content; // for text content index
|
2020-12-30 15:31:36 +08:00
|
|
|
QString *m_index_data_path;
|
2021-01-19 10:44:28 +08:00
|
|
|
Xapian::WritableDatabase *m_database_path;
|
2020-12-30 15:31:36 +08:00
|
|
|
Xapian::WritableDatabase *m_database_content;
|
|
|
|
std::string m_docstr;
|
|
|
|
std::string m_index_text_str;
|
|
|
|
Xapian::TermGenerator *m_indexer;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INDEXGENERATOR_H
|