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 FILESEARCHER_H
|
|
|
|
#define FILESEARCHER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <xapian.h>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QVector>
|
2021-01-02 17:21:38 +08:00
|
|
|
#include <QMap>
|
2021-01-08 19:08:24 +08:00
|
|
|
#include <QQueue>
|
|
|
|
#include <QPair>
|
2021-01-10 15:59:17 +08:00
|
|
|
#include <QMutex>
|
2021-03-08 10:02:53 +08:00
|
|
|
#define INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/ukui-search/index_data").toStdString()
|
|
|
|
#define CONTENT_INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/ukui-search/content_index_data").toStdString()
|
2020-12-30 15:31:36 +08:00
|
|
|
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
class FileSearcher : public QObject {
|
2020-12-30 15:31:36 +08:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit FileSearcher(QObject *parent = nullptr);
|
2021-01-10 15:59:17 +08:00
|
|
|
~FileSearcher();
|
2020-12-30 15:31:36 +08:00
|
|
|
|
2021-01-15 16:16:51 +08:00
|
|
|
static int getCurrentIndexCount();
|
2021-01-15 09:14:25 +08:00
|
|
|
|
2021-01-11 20:34:51 +08:00
|
|
|
static size_t uniqueSymbol1;
|
|
|
|
static size_t uniqueSymbol2;
|
|
|
|
static size_t uniqueSymbol3;
|
|
|
|
static QMutex m_mutex1;
|
|
|
|
static QMutex m_mutex2;
|
|
|
|
static QMutex m_mutex3;
|
|
|
|
|
2020-12-30 15:31:36 +08:00
|
|
|
public Q_SLOTS:
|
2021-04-26 15:06:47 +08:00
|
|
|
void onKeywordSearch(QString keyword, QQueue<QString> *searchResultFile, QQueue<QString> *searchResultDir, QQueue<QPair<QString, QStringList>> *searchResultContent);
|
2020-12-30 15:31:36 +08:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
2021-01-08 19:08:24 +08:00
|
|
|
void resultFile(QQueue<QString> *);
|
|
|
|
void resultDir(QQueue<QString> *);
|
2021-04-26 15:06:47 +08:00
|
|
|
void resultContent(QQueue<QPair<QString, QStringList>> *);
|
2020-12-30 15:31:36 +08:00
|
|
|
private:
|
2021-04-26 15:06:47 +08:00
|
|
|
int keywordSearchfile(size_t uniqueSymbol, QString keyword, QString value, unsigned slot = 1, int begin = 0, int num = 20);
|
2021-01-10 15:59:17 +08:00
|
|
|
int keywordSearchContent(size_t uniqueSymbol, QString keyword, int begin = 0, int num = 20);
|
2021-01-08 19:08:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief FileSearcher::creatQueryForFileSearch
|
|
|
|
* This part shall be optimized frequently to provide a more stable search function.
|
|
|
|
* @param keyword
|
|
|
|
* @param db
|
|
|
|
* @return Xapian::Query
|
|
|
|
*/
|
|
|
|
Xapian::Query creatQueryForFileSearch(QString keyword, Xapian::Database &db);
|
|
|
|
Xapian::Query creatQueryForContentSearch(QString keyword, Xapian::Database &db);
|
|
|
|
|
2021-01-11 20:49:42 +08:00
|
|
|
int getResult(size_t uniqueSymbol, Xapian::MSet &result, QString value);
|
2021-04-26 15:06:47 +08:00
|
|
|
int getContentResult(size_t uniqueSymbol, Xapian::MSet &result, std::string &keyWord);
|
2021-01-08 19:08:24 +08:00
|
|
|
|
|
|
|
bool isBlocked(QString &path);
|
2021-01-10 15:59:17 +08:00
|
|
|
|
2021-01-08 20:48:20 +08:00
|
|
|
QQueue<QString> *m_search_result_file = nullptr;
|
|
|
|
QQueue<QString> *m_search_result_dir = nullptr;
|
2021-04-26 15:06:47 +08:00
|
|
|
QQueue<QPair<QString, QStringList>> *m_search_result_content = nullptr;
|
2021-01-10 15:59:17 +08:00
|
|
|
bool m_searching = false;
|
2020-12-30 15:31:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // FILESEARCHER_H
|