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

66 lines
2.0 KiB
C
Raw Normal View History

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>
2020-12-30 15:31:36 +08:00
#include "document.h"
#include "file-reader.h"
//#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:
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);
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);
private:
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
QMap<QString,QStringList> *m_index_map;
// 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;
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