2020-12-21 18:50:54 +08:00
|
|
|
#ifndef INDEXGENERATOR_H
|
|
|
|
#define INDEXGENERATOR_H
|
|
|
|
|
|
|
|
#include <xapian.h>
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
#include <QStringList>
|
2020-12-22 21:20:47 +08:00
|
|
|
#include <QMap>
|
2020-12-21 18:50:54 +08:00
|
|
|
#include <QCryptographicHash>
|
2020-12-26 08:56:38 +08:00
|
|
|
#include "document.h"
|
2020-12-29 20:18:36 +08:00
|
|
|
#include "file-reader.h"
|
2020-12-21 18:50:54 +08:00
|
|
|
|
|
|
|
class IndexGenerator : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static IndexGenerator *getInstance();
|
2020-12-22 21:20:47 +08:00
|
|
|
bool setIndexdataPath();
|
2020-12-21 18:50:54 +08:00
|
|
|
bool isIndexdataExist();
|
2020-12-22 21:20:47 +08:00
|
|
|
static QStringList IndexSearch(QString indexText);
|
2020-12-21 18:50:54 +08:00
|
|
|
Q_SIGNALS:
|
|
|
|
void transactionFinished();
|
|
|
|
void searchFinish();
|
|
|
|
public Q_SLOTS:
|
2020-12-26 08:56:38 +08:00
|
|
|
bool creatAllIndex(QList<QVector<QString>> *messageList);
|
2020-12-29 20:18:36 +08:00
|
|
|
bool creatAllIndex(QVector<QString> *messageList);
|
2020-12-21 18:50:54 +08:00
|
|
|
bool deleteAllIndex(QStringList *pathlist);
|
2020-12-22 21:20:47 +08:00
|
|
|
|
2020-12-21 18:50:54 +08:00
|
|
|
private:
|
|
|
|
explicit IndexGenerator(QObject *parent = nullptr);
|
2020-12-29 20:18:36 +08:00
|
|
|
//For file name index
|
2020-12-26 08:56:38 +08:00
|
|
|
void HandlePathList(QList<QVector<QString>> *messageList);
|
2020-12-29 20:18:36 +08:00
|
|
|
//For file content index
|
|
|
|
void HandlePathList(QVector<QString> *messageList);
|
2020-12-26 08:56:38 +08:00
|
|
|
static Document GenerateDocument(const QVector<QString> &list);
|
2020-12-29 20:18:36 +08:00
|
|
|
static Document GenerateContentDocument(const QString &list);
|
2020-12-21 18:50:54 +08:00
|
|
|
//add one data in database
|
2020-12-26 08:56:38 +08:00
|
|
|
void insertIntoDatabase(Document doc);
|
2020-12-21 18:50:54 +08:00
|
|
|
~IndexGenerator();
|
|
|
|
|
2020-12-24 20:38:26 +08:00
|
|
|
QMap<QString,QStringList> *m_index_map;
|
2020-12-29 20:18:36 +08:00
|
|
|
QList<Document> *m_doc_list_path; //for path index
|
|
|
|
QList<Document> *m_doc_list_content; // for text content index
|
2020-12-21 18:50:54 +08:00
|
|
|
QString *m_index_data_path;
|
2020-12-29 20:18:36 +08:00
|
|
|
Xapian::WritableDatabase *m_datebase_path;
|
|
|
|
Xapian::WritableDatabase *m_database_content;
|
2020-12-21 18:50:54 +08:00
|
|
|
std::string m_docstr;
|
|
|
|
std::string m_index_text_str;
|
|
|
|
Xapian::TermGenerator *m_indexer;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INDEXGENERATOR_H
|