2021-03-17 10:23:21 +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>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef SEARCHMANAGER_H
|
|
|
|
#define SEARCHMANAGER_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <xapian.h>
|
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QVector>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QQueue>
|
|
|
|
#include <QPair>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <thread>
|
|
|
|
#include <QRunnable>
|
|
|
|
#include <QThreadPool>
|
2021-04-16 11:20:14 +08:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QtConcurrent/QtConcurrent>
|
|
|
|
#include <QThread>
|
|
|
|
#include <QUrl>
|
2022-10-26 18:01:40 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2022, 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: iaom <zhangpengfei@kylinos.cn>
|
|
|
|
*
|
|
|
|
*/
|
2021-05-27 21:10:11 +08:00
|
|
|
#include "search-plugin-iface.h"
|
2021-05-07 20:48:15 +08:00
|
|
|
#include "file-utils.h"
|
|
|
|
#include "global-settings.h"
|
|
|
|
#include "chinese-segmentation.h"
|
2021-05-27 21:10:11 +08:00
|
|
|
#include "common.h"
|
2021-03-17 10:23:21 +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()
|
2023-09-28 10:54:58 +08:00
|
|
|
#define OCR_CONTENT_INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/ukui-search/ocr_content_index_data").toStdString()
|
2021-12-14 14:43:35 +08:00
|
|
|
namespace UkuiSearch {
|
2021-11-10 10:20:16 +08:00
|
|
|
class FileMatchDecider;
|
|
|
|
class FileContentMatchDecider;
|
2022-01-21 16:53:19 +08:00
|
|
|
class OcrMatchDecider;
|
2021-04-30 16:28:50 +08:00
|
|
|
class LIBSEARCH_EXPORT SearchManager : public QObject {
|
2021-03-17 10:23:21 +08:00
|
|
|
friend class FileSearch;
|
|
|
|
friend class FileContentSearch;
|
2022-01-21 16:53:19 +08:00
|
|
|
friend class OcrSearch;
|
2021-05-27 21:10:11 +08:00
|
|
|
friend class DirectSearch;
|
2021-11-10 10:20:16 +08:00
|
|
|
friend class FileMatchDecider;
|
|
|
|
friend class FileContentMatchDecider;
|
2022-01-21 16:53:19 +08:00
|
|
|
friend class OcrMatchDecider;
|
2021-03-17 10:23:21 +08:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit SearchManager(QObject *parent = nullptr);
|
|
|
|
~SearchManager();
|
|
|
|
|
2023-09-28 10:54:58 +08:00
|
|
|
static uint getCurrentIndexCount();
|
2021-03-17 10:23:21 +08:00
|
|
|
|
2021-08-24 17:14:28 +08:00
|
|
|
static size_t uniqueSymbolFile;
|
|
|
|
static size_t uniqueSymbolDir;
|
|
|
|
static size_t uniqueSymbolContent;
|
2022-01-21 16:53:19 +08:00
|
|
|
static size_t uniqueSymbolOcr;
|
2021-08-24 17:14:28 +08:00
|
|
|
static QMutex m_mutexFile;
|
|
|
|
static QMutex m_mutexDir;
|
|
|
|
static QMutex m_mutexContent;
|
2022-01-21 16:53:19 +08:00
|
|
|
static QMutex m_mutexOcr;
|
2021-03-17 10:23:21 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
static bool isBlocked(QString &path);
|
2023-09-28 10:54:58 +08:00
|
|
|
static bool creatResultInfo(UkuiSearch::SearchPluginIface::ResultInfo &ri, const QString& path);
|
2021-03-17 10:23:21 +08:00
|
|
|
};
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
class FileSearch : public QRunnable {
|
2021-03-17 10:23:21 +08:00
|
|
|
public:
|
2021-05-27 21:10:11 +08:00
|
|
|
explicit FileSearch(DataQueue<SearchPluginIface::ResultInfo> *searchResult, size_t uniqueSymbol, QString keyword, QString value, unsigned slot = 1, int begin = 0, int num = 20);
|
2021-03-17 10:23:21 +08:00
|
|
|
~FileSearch();
|
|
|
|
protected:
|
|
|
|
void run();
|
|
|
|
private:
|
2023-09-28 10:54:58 +08:00
|
|
|
uint keywordSearchFile();
|
2023-04-24 14:07:56 +08:00
|
|
|
Xapian::Query creatQueryForFileSearch();
|
2021-03-17 10:23:21 +08:00
|
|
|
int getResult(Xapian::MSet &result);
|
|
|
|
|
2021-05-27 21:10:11 +08:00
|
|
|
DataQueue<SearchPluginIface::ResultInfo> *m_search_result = nullptr;
|
2021-11-10 10:20:16 +08:00
|
|
|
FileMatchDecider *m_matchDecider;
|
2021-03-17 10:23:21 +08:00
|
|
|
QString m_value;
|
|
|
|
unsigned m_slot = 1;
|
|
|
|
size_t m_uniqueSymbol;
|
|
|
|
QString m_keyword;
|
|
|
|
int m_begin = 0;
|
|
|
|
int m_num = 20;
|
|
|
|
};
|
2021-04-16 15:35:54 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
class FileContentSearch : public QRunnable {
|
2021-03-17 10:23:21 +08:00
|
|
|
public:
|
2022-11-28 18:11:55 +08:00
|
|
|
explicit FileContentSearch(DataQueue<SearchPluginIface::ResultInfo> *searchResult, size_t uniqueSymbol, QString keyword, bool fuzzy,int begin = 0, int num = 20);
|
2021-03-17 10:23:21 +08:00
|
|
|
~FileContentSearch();
|
|
|
|
protected:
|
|
|
|
void run();
|
|
|
|
private:
|
2023-09-28 10:54:58 +08:00
|
|
|
uint keywordSearchContent();
|
2021-04-26 15:06:47 +08:00
|
|
|
int getResult(Xapian::MSet &result, std::string &keyWord);
|
2021-03-17 10:23:21 +08:00
|
|
|
|
2021-05-27 21:10:11 +08:00
|
|
|
DataQueue<SearchPluginIface::ResultInfo> *m_search_result = nullptr;
|
2021-11-10 10:20:16 +08:00
|
|
|
FileContentMatchDecider *m_matchDecider;
|
2021-03-17 10:23:21 +08:00
|
|
|
size_t m_uniqueSymbol;
|
|
|
|
QString m_keyword;
|
2022-11-28 18:11:55 +08:00
|
|
|
bool m_fuzzy;
|
2021-03-17 10:23:21 +08:00
|
|
|
int m_begin = 0;
|
|
|
|
int m_num = 20;
|
|
|
|
};
|
2021-04-16 15:35:54 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
class DirectSearch : public QRunnable {
|
2021-04-16 15:35:54 +08:00
|
|
|
public:
|
2021-05-27 21:10:11 +08:00
|
|
|
explicit DirectSearch(QString keyword, DataQueue<SearchPluginIface::ResultInfo> *searchResult, QString value, size_t uniqueSymbol);
|
2021-04-16 15:35:54 +08:00
|
|
|
protected:
|
|
|
|
void run();
|
|
|
|
private:
|
2023-04-21 11:22:41 +08:00
|
|
|
void match(const QFileInfo& info);
|
2021-04-16 15:35:54 +08:00
|
|
|
QString m_keyword;
|
2021-05-27 21:10:11 +08:00
|
|
|
DataQueue<SearchPluginIface::ResultInfo>* m_searchResult = nullptr;
|
2021-04-16 15:35:54 +08:00
|
|
|
size_t m_uniqueSymbol;
|
2021-05-27 21:10:11 +08:00
|
|
|
QString m_value;
|
2021-04-16 15:35:54 +08:00
|
|
|
};
|
2021-04-30 16:28:50 +08:00
|
|
|
|
2022-01-21 16:53:19 +08:00
|
|
|
class FileMatchDecider : public Xapian::MatchDecider {
|
|
|
|
public:
|
|
|
|
bool operator ()(const Xapian::Document &doc) const;
|
|
|
|
};
|
|
|
|
class FileContentMatchDecider : public Xapian::MatchDecider {
|
2021-11-10 10:20:16 +08:00
|
|
|
public:
|
|
|
|
bool operator ()(const Xapian::Document &doc) const;
|
|
|
|
};
|
|
|
|
|
2021-04-30 16:28:50 +08:00
|
|
|
}
|
2021-03-17 10:23:21 +08:00
|
|
|
#endif // SEARCHMANAGER_H
|