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
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDebug>
|
2021-01-08 19:08:24 +08:00
|
|
|
#include <QtConcurrent>
|
2021-01-10 15:59:17 +08:00
|
|
|
#include <QThread>
|
2021-01-03 16:01:35 +08:00
|
|
|
#include <chinese-segmentation.h>
|
2021-01-27 18:22:50 +08:00
|
|
|
#include <QUrl>
|
2021-01-08 19:08:24 +08:00
|
|
|
#include "file-searcher.h"
|
|
|
|
#include "global-settings.h"
|
|
|
|
|
2021-01-10 15:59:17 +08:00
|
|
|
size_t FileSearcher::uniqueSymbol1 = 0;
|
|
|
|
size_t FileSearcher::uniqueSymbol2 = 0;
|
|
|
|
size_t FileSearcher::uniqueSymbol3 = 0;
|
|
|
|
QMutex FileSearcher::m_mutex1;
|
|
|
|
QMutex FileSearcher::m_mutex2;
|
|
|
|
QMutex FileSearcher::m_mutex3;
|
2021-04-26 15:06:47 +08:00
|
|
|
FileSearcher::FileSearcher(QObject *parent) : QObject(parent) {
|
2021-01-08 19:08:24 +08:00
|
|
|
}
|
2020-12-30 15:31:36 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
FileSearcher::~FileSearcher() {
|
2021-01-10 15:59:17 +08:00
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
int FileSearcher::getCurrentIndexCount() {
|
|
|
|
try {
|
2021-01-19 10:44:28 +08:00
|
|
|
Xapian::Database db(INDEX_PATH);
|
|
|
|
return db.get_doccount();
|
2021-04-26 15:06:47 +08:00
|
|
|
} catch(const Xapian::Error &e) {
|
|
|
|
qWarning() << QString::fromStdString(e.get_description());
|
2021-01-19 10:44:28 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2021-01-15 09:14:25 +08:00
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
void FileSearcher::onKeywordSearch(QString keyword, QQueue<QString> *searchResultFile, QQueue<QString> *searchResultDir, QQueue<QPair<QString, QStringList>> *searchResultContent) {
|
2021-01-10 15:59:17 +08:00
|
|
|
m_mutex1.lock();
|
|
|
|
++uniqueSymbol1;
|
|
|
|
m_mutex1.unlock();
|
|
|
|
m_mutex2.lock();
|
|
|
|
++uniqueSymbol2;
|
|
|
|
m_mutex2.unlock();
|
|
|
|
m_mutex3.lock();
|
|
|
|
++uniqueSymbol3;
|
|
|
|
m_mutex3.unlock();
|
2021-01-11 18:36:04 +08:00
|
|
|
|
|
|
|
m_search_result_file = searchResultFile;
|
|
|
|
m_search_result_dir = searchResultDir;
|
|
|
|
m_search_result_content = searchResultContent;
|
|
|
|
|
2021-01-08 19:08:24 +08:00
|
|
|
//file
|
2021-04-26 15:06:47 +08:00
|
|
|
QtConcurrent::run([&, uniqueSymbol1, keyword]() {
|
2021-01-10 15:59:17 +08:00
|
|
|
if(!m_search_result_file->isEmpty())
|
|
|
|
m_search_result_file->clear();
|
2021-01-08 19:08:24 +08:00
|
|
|
int begin = 0;
|
2021-01-10 15:59:17 +08:00
|
|
|
int num = 5;
|
2021-01-08 19:08:24 +08:00
|
|
|
int resultCount = 0;
|
2021-01-10 15:59:17 +08:00
|
|
|
int total = 0;
|
2021-04-26 15:06:47 +08:00
|
|
|
while(total < 100) {
|
|
|
|
resultCount = keywordSearchfile(uniqueSymbol1, keyword, "0", 1, begin, num);
|
2021-01-08 19:08:24 +08:00
|
|
|
if(resultCount == 0 || resultCount == -1)
|
|
|
|
break;
|
2021-01-10 15:59:17 +08:00
|
|
|
total += resultCount;
|
2021-01-08 19:08:24 +08:00
|
|
|
begin += num;
|
|
|
|
}
|
2021-01-21 13:50:21 +08:00
|
|
|
return;
|
2021-01-08 19:08:24 +08:00
|
|
|
});
|
2021-01-26 16:50:30 +08:00
|
|
|
// Q_EMIT this->resultFile(m_search_result_file);
|
2021-01-08 19:08:24 +08:00
|
|
|
//dir
|
2021-04-26 15:06:47 +08:00
|
|
|
QtConcurrent::run([&, uniqueSymbol2, keyword]() {
|
2021-01-10 15:59:17 +08:00
|
|
|
if(!m_search_result_dir->isEmpty())
|
|
|
|
m_search_result_dir->clear();
|
2021-01-08 19:08:24 +08:00
|
|
|
int begin = 0;
|
2021-01-10 15:59:17 +08:00
|
|
|
int num = 5;
|
2021-01-08 19:08:24 +08:00
|
|
|
int resultCount = 0;
|
2021-01-10 15:59:17 +08:00
|
|
|
int total = 0;
|
2021-04-26 15:06:47 +08:00
|
|
|
while(total < 100) {
|
|
|
|
resultCount = keywordSearchfile(uniqueSymbol2, keyword, "1", 1, begin, num);
|
2021-01-08 19:08:24 +08:00
|
|
|
if(resultCount == 0 || resultCount == -1)
|
|
|
|
break;
|
2021-01-10 15:59:17 +08:00
|
|
|
total += resultCount;
|
2021-01-08 19:08:24 +08:00
|
|
|
begin += num;
|
|
|
|
}
|
2021-01-21 13:50:21 +08:00
|
|
|
return;
|
2021-01-08 19:08:24 +08:00
|
|
|
});
|
2021-01-26 16:50:30 +08:00
|
|
|
// Q_EMIT this->resultDir(m_search_result_dir);
|
2021-01-08 19:08:24 +08:00
|
|
|
//content
|
2021-04-26 15:06:47 +08:00
|
|
|
QtConcurrent::run([&, uniqueSymbol3, keyword]() {
|
2021-01-10 15:59:17 +08:00
|
|
|
if(!m_search_result_content->isEmpty())
|
|
|
|
m_search_result_content->clear();
|
2021-01-08 19:08:24 +08:00
|
|
|
int begin = 0;
|
2021-01-10 15:59:17 +08:00
|
|
|
int num = 5;
|
2021-01-08 19:08:24 +08:00
|
|
|
int resultCount = 0;
|
2021-01-10 15:59:17 +08:00
|
|
|
int total = 0;
|
2021-01-11 20:34:51 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
while(total < 50) {
|
|
|
|
resultCount = keywordSearchContent(uniqueSymbol3, keyword, begin, num);
|
2021-01-08 19:08:24 +08:00
|
|
|
if(resultCount == 0 || resultCount == -1)
|
|
|
|
break;
|
2021-01-10 15:59:17 +08:00
|
|
|
total += resultCount;
|
2021-01-08 19:08:24 +08:00
|
|
|
begin += num;
|
|
|
|
}
|
2021-01-21 13:50:21 +08:00
|
|
|
return;
|
2021-01-08 19:08:24 +08:00
|
|
|
});
|
2021-01-26 16:50:30 +08:00
|
|
|
// Q_EMIT this->resultContent(m_search_result_content);
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
int FileSearcher::keywordSearchfile(size_t uniqueSymbol, QString keyword, QString value, unsigned slot, int begin, int num) {
|
|
|
|
try {
|
2021-01-26 16:50:30 +08:00
|
|
|
qDebug() << "--keywordSearchfile start--";
|
2020-12-30 15:31:36 +08:00
|
|
|
Xapian::Database db(INDEX_PATH);
|
2021-04-26 15:06:47 +08:00
|
|
|
Xapian::Query query = creatQueryForFileSearch(keyword, db);
|
2020-12-30 15:31:36 +08:00
|
|
|
Xapian::Enquire enquire(db);
|
|
|
|
|
2021-01-08 19:08:24 +08:00
|
|
|
Xapian::Query queryFile;
|
2021-04-26 15:06:47 +08:00
|
|
|
if(!value.isEmpty()) {
|
2021-01-08 19:08:24 +08:00
|
|
|
std::string slotValue = value.toStdString();
|
2021-04-26 15:06:47 +08:00
|
|
|
Xapian::Query queryValue = Xapian::Query(Xapian::Query::OP_VALUE_RANGE, slot, slotValue, slotValue);
|
|
|
|
queryFile = Xapian::Query(Xapian::Query::OP_AND, query, queryValue);
|
|
|
|
} else {
|
2021-01-08 19:08:24 +08:00
|
|
|
queryFile = query;
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
qDebug() << "keywordSearchfile:" << QString::fromStdString(queryFile.get_description());
|
2020-12-30 15:31:36 +08:00
|
|
|
|
|
|
|
enquire.set_query(queryFile);
|
2021-01-26 16:50:30 +08:00
|
|
|
Xapian::MSet result = enquire.get_mset(begin, num);
|
|
|
|
int resultCount = result.size();
|
2021-04-26 15:06:47 +08:00
|
|
|
qDebug() << "keywordSearchfile results count=" << resultCount;
|
2021-01-11 20:49:42 +08:00
|
|
|
if(result.size() == 0)
|
|
|
|
return 0;
|
|
|
|
if(getResult(uniqueSymbol, result, value) == -1)
|
|
|
|
return -1;
|
2020-12-30 15:31:36 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
qDebug() << "--keywordSearchfile finish--";
|
2021-01-08 19:08:24 +08:00
|
|
|
return resultCount;
|
2021-04-26 15:06:47 +08:00
|
|
|
} catch(const Xapian::Error &e) {
|
|
|
|
qWarning() << QString::fromStdString(e.get_description());
|
|
|
|
qDebug() << "--keywordSearchfile finish--";
|
2021-01-08 19:08:24 +08:00
|
|
|
return -1;
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
int FileSearcher::keywordSearchContent(size_t uniqueSymbol, QString keyword, int begin, int num) {
|
|
|
|
try {
|
|
|
|
qDebug() << "--keywordSearchContent search start--";
|
2020-12-31 21:14:13 +08:00
|
|
|
|
|
|
|
Xapian::Database db(CONTENT_INDEX_PATH);
|
|
|
|
Xapian::Enquire enquire(db);
|
|
|
|
Xapian::QueryParser qp;
|
2021-01-03 16:01:35 +08:00
|
|
|
qp.set_default_op(Xapian::Query::OP_AND);
|
2020-12-31 21:14:13 +08:00
|
|
|
qp.set_database(db);
|
|
|
|
|
2021-01-19 10:44:28 +08:00
|
|
|
QVector<SKeyWord> sKeyWord = ChineseSegmentation::getInstance()->callSegement(keyword);
|
2020-12-31 21:14:13 +08:00
|
|
|
//Creat a query
|
2021-01-03 16:01:35 +08:00
|
|
|
std::string words;
|
2021-04-26 15:06:47 +08:00
|
|
|
for(int i = 0; i < sKeyWord.size(); i++) {
|
2021-01-03 16:01:35 +08:00
|
|
|
words.append(sKeyWord.at(i).word).append(" ");
|
|
|
|
}
|
|
|
|
Xapian::Query query = qp.parse_query(words);
|
|
|
|
|
2021-01-26 16:50:30 +08:00
|
|
|
// std::vector<Xapian::Query> v;
|
|
|
|
// for(int i=0;i<sKeyWord.size();i++)
|
|
|
|
// {
|
|
|
|
// v.push_back(Xapian::Query(sKeyWord.at(i).word));
|
|
|
|
// qDebug()<<QString::fromStdString(sKeyWord.at(i).word);
|
|
|
|
// }
|
|
|
|
// Xapian::Query queryPhrase =Xapian::Query(Xapian::Query::OP_AND, v.begin(), v.end());
|
2021-04-26 15:06:47 +08:00
|
|
|
qDebug() << "keywordSearchContent:" << QString::fromStdString(query.get_description());
|
2020-12-31 21:14:13 +08:00
|
|
|
|
2021-01-03 16:01:35 +08:00
|
|
|
enquire.set_query(query);
|
2021-01-25 19:16:22 +08:00
|
|
|
|
2021-01-26 16:50:30 +08:00
|
|
|
Xapian::MSet result = enquire.get_mset(begin, num);
|
|
|
|
int resultCount = result.size();
|
2021-01-11 20:49:42 +08:00
|
|
|
if(result.size() == 0)
|
|
|
|
return 0;
|
2021-04-26 15:06:47 +08:00
|
|
|
qDebug() << "keywordSearchContent results count=" << resultCount;
|
2021-01-03 16:01:35 +08:00
|
|
|
|
2021-01-11 20:49:42 +08:00
|
|
|
if(getContentResult(uniqueSymbol, result, words) == -1)
|
|
|
|
return -1;
|
2020-12-31 21:14:13 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
qDebug() << "--keywordSearchContent search finish--";
|
2021-01-08 19:08:24 +08:00
|
|
|
return resultCount;
|
2021-04-26 15:06:47 +08:00
|
|
|
} catch(const Xapian::Error &e) {
|
|
|
|
qWarning() << QString::fromStdString(e.get_description());
|
|
|
|
qDebug() << "--keywordSearchContent search finish--";
|
2021-01-08 19:08:24 +08:00
|
|
|
return -1;
|
2020-12-31 21:14:13 +08:00
|
|
|
}
|
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
Xapian::Query FileSearcher::creatQueryForFileSearch(QString keyword, Xapian::Database &db) {
|
2021-03-01 09:07:33 +08:00
|
|
|
// Xapian::QueryParser qp;
|
|
|
|
// qp.set_default_op(Xapian::Query::OP_PHRASE);
|
|
|
|
// qp.set_database(db);
|
|
|
|
auto userInput = keyword.toLower();
|
|
|
|
// userInput = userInput.replace(".","").simplified();
|
|
|
|
// userInput = QString(QUrl::toPercentEncoding(userInput)).replace(""," ").simplified();
|
2021-01-08 19:08:24 +08:00
|
|
|
|
2021-01-26 16:50:30 +08:00
|
|
|
// std::string queryStr = keyword.replace(".","").replace(" ","").replace(""," ").simplified().toStdString();
|
|
|
|
// std::string s =db.get_spelling_suggestion(queryStr,10);
|
|
|
|
// qDebug()<<"spelling_suggestion!"<<QString::fromStdString(s);
|
2021-01-08 19:08:24 +08:00
|
|
|
|
2021-01-26 16:50:30 +08:00
|
|
|
// qDebug()<<"queryStr!"<<QString::fromStdString(queryStr);
|
2021-01-08 19:08:24 +08:00
|
|
|
//Creat a query
|
2021-03-01 09:07:33 +08:00
|
|
|
// Xapian::Query queryPhrase = qp.parse_query(userInput.toStdString(),Xapian::QueryParser::FLAG_PHRASE|Xapian::QueryParser::FLAG_SYNONYM);
|
2021-01-08 19:08:24 +08:00
|
|
|
std::vector<Xapian::Query> v;
|
2021-04-26 15:06:47 +08:00
|
|
|
for(int i = 0; i < userInput.size(); i++) {
|
2021-01-27 18:22:50 +08:00
|
|
|
v.push_back(Xapian::Query(QUrl::toPercentEncoding(userInput.at(i)).toStdString()));
|
2021-01-26 16:50:30 +08:00
|
|
|
// qDebug()<<QString::fromStdString(Xapian::Query(QString(userInput.at(i)).toStdString()).get_description());
|
2021-01-08 19:08:24 +08:00
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
Xapian::Query queryPhrase = Xapian::Query(Xapian::Query::OP_PHRASE, v.begin(), v.end());
|
2021-02-20 16:56:30 +08:00
|
|
|
// Xapian::Query queryNear =Xapian::Query(Xapian::Query::OP_NEAR, v.begin(), v.end());
|
2020-12-31 21:14:13 +08:00
|
|
|
|
2021-02-20 16:56:30 +08:00
|
|
|
// Xapian::Query query = Xapian::Query(Xapian::Query::OP_AND,queryNear,queryPhrase);
|
2021-01-26 16:50:30 +08:00
|
|
|
// qDebug()<<QString::fromStdString(query.get_description());
|
2021-02-20 16:56:30 +08:00
|
|
|
return queryPhrase;
|
2021-01-08 19:08:24 +08:00
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
Xapian::Query FileSearcher::creatQueryForContentSearch(QString keyword, Xapian::Database &db) {
|
2021-01-08 19:08:24 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
int FileSearcher::getResult(size_t uniqueSymbol, Xapian::MSet &result, QString value) {
|
2020-12-30 15:31:36 +08:00
|
|
|
//QStringList *pathTobeDelete = new QStringList;
|
|
|
|
//Delete those path doc which is not already exist.
|
|
|
|
|
2021-01-26 16:50:30 +08:00
|
|
|
// QStringList searchResult = QStringList();
|
2021-01-02 17:21:38 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
for(auto it = result.begin(); it != result.end(); ++it) {
|
2020-12-30 15:31:36 +08:00
|
|
|
Xapian::Document doc = it.get_document();
|
|
|
|
std::string data = doc.get_data();
|
|
|
|
Xapian::weight docScoreWeight = it.get_weight();
|
|
|
|
Xapian::percent docScorePercent = it.get_percent();
|
2021-01-08 19:08:24 +08:00
|
|
|
QString path = QString::fromStdString(data);
|
|
|
|
|
|
|
|
if(isBlocked(path))
|
|
|
|
continue;
|
|
|
|
|
2021-01-10 15:59:17 +08:00
|
|
|
QFileInfo info(path);
|
2020-12-30 15:31:36 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
if(!info.exists()) {
|
2021-01-26 16:50:30 +08:00
|
|
|
// pathTobeDelete->append(QString::fromStdString(data));
|
2021-04-26 15:06:47 +08:00
|
|
|
qDebug() << path << "is not exist!!";
|
|
|
|
} else {
|
|
|
|
switch(value.toInt()) {
|
2021-01-08 19:08:24 +08:00
|
|
|
case 1:
|
2021-01-10 15:59:17 +08:00
|
|
|
m_mutex1.lock();
|
2021-04-26 15:06:47 +08:00
|
|
|
if(uniqueSymbol == FileSearcher::uniqueSymbol1) {
|
2021-01-10 15:59:17 +08:00
|
|
|
m_search_result_dir->enqueue(path);
|
|
|
|
m_mutex1.unlock();
|
2021-04-26 15:06:47 +08:00
|
|
|
} else {
|
2021-01-10 15:59:17 +08:00
|
|
|
m_mutex1.unlock();
|
2021-01-11 20:49:42 +08:00
|
|
|
return -1;
|
2021-01-10 15:59:17 +08:00
|
|
|
}
|
|
|
|
|
2021-01-08 19:08:24 +08:00
|
|
|
break;
|
|
|
|
case 0:
|
2021-01-10 15:59:17 +08:00
|
|
|
m_mutex2.lock();
|
2021-04-26 15:06:47 +08:00
|
|
|
if(uniqueSymbol == FileSearcher::uniqueSymbol2) {
|
2021-01-10 15:59:17 +08:00
|
|
|
m_search_result_file->enqueue(path);
|
|
|
|
m_mutex2.unlock();
|
2021-04-26 15:06:47 +08:00
|
|
|
} else {
|
2021-01-10 15:59:17 +08:00
|
|
|
m_mutex2.unlock();
|
2021-01-11 20:49:42 +08:00
|
|
|
return -1;
|
2021-01-10 15:59:17 +08:00
|
|
|
}
|
2021-01-08 19:08:24 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2021-01-26 16:50:30 +08:00
|
|
|
// searchResult.append(path);
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
2021-04-26 15:06:47 +08:00
|
|
|
qDebug() << "doc=" << path << ",weight=" << docScoreWeight << ",percent=" << docScorePercent;
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
|
|
|
// if(!pathTobeDelete->isEmpty())
|
|
|
|
// deleteAllIndex(pathTobeDelete)
|
2021-01-11 20:49:42 +08:00
|
|
|
return 0;
|
2020-12-30 15:31:36 +08:00
|
|
|
}
|
2021-01-02 17:21:38 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
int FileSearcher::getContentResult(size_t uniqueSymbol, Xapian::MSet &result, std::string &keyWord) {
|
2021-01-02 17:21:38 +08:00
|
|
|
//QStringList *pathTobeDelete = new QStringList;
|
|
|
|
//Delete those path doc which is not already exist.
|
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
QString wordTobeFound = QString::fromStdString(keyWord).section(" ", 0, 0);
|
2021-01-03 16:01:35 +08:00
|
|
|
int size = wordTobeFound.size();
|
|
|
|
int totalSize = QString::fromStdString(keyWord).size();
|
|
|
|
if(totalSize < 5)
|
|
|
|
totalSize = 5;
|
2021-01-26 16:50:30 +08:00
|
|
|
// QMap<QString,QStringList> searchResult;
|
2021-01-02 17:21:38 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
for(auto it = result.begin(); it != result.end(); ++it) {
|
2021-01-02 17:21:38 +08:00
|
|
|
Xapian::Document doc = it.get_document();
|
|
|
|
std::string data = doc.get_data();
|
|
|
|
double docScoreWeight = it.get_weight();
|
|
|
|
Xapian::percent docScorePercent = it.get_percent();
|
|
|
|
QString path = QString::fromStdString(doc.get_value(1));
|
2021-01-08 19:08:24 +08:00
|
|
|
|
|
|
|
if(isBlocked(path))
|
|
|
|
continue;
|
|
|
|
|
2021-01-10 15:59:17 +08:00
|
|
|
QFileInfo info(path);
|
2021-01-02 17:21:38 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
if(!info.exists()) {
|
2021-01-02 17:21:38 +08:00
|
|
|
// pathTobeDelete->append(QString::fromStdString(data));
|
2021-04-26 15:06:47 +08:00
|
|
|
qDebug() << path << "is not exist!!";
|
2021-01-02 17:21:38 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Construct snippets containing keyword.
|
|
|
|
QStringList snippets;
|
|
|
|
auto term = doc.termlist_begin();
|
2021-01-03 16:01:35 +08:00
|
|
|
term.skip_to(wordTobeFound.toStdString());
|
2021-04-26 15:06:47 +08:00
|
|
|
int count = 0;
|
|
|
|
for(auto pos = term.positionlist_begin(); pos != term.positionlist_end() && count < 6; ++pos) {
|
2021-01-02 17:21:38 +08:00
|
|
|
QByteArray snippetByte = QByteArray::fromStdString(data);
|
2021-04-26 15:06:47 +08:00
|
|
|
QString snippet = "..." + QString(snippetByte.left(*pos)).right(size + totalSize) + QString(snippetByte.mid(*pos, -1)).left(size + totalSize) + "...";
|
2021-01-26 16:50:30 +08:00
|
|
|
// qDebug()<<snippet;
|
2021-01-02 17:21:38 +08:00
|
|
|
snippets.append(snippet);
|
2021-01-03 16:01:35 +08:00
|
|
|
++count;
|
2021-01-02 17:21:38 +08:00
|
|
|
}
|
2021-01-10 15:59:17 +08:00
|
|
|
m_mutex3.lock();
|
2021-04-26 15:06:47 +08:00
|
|
|
if(uniqueSymbol == FileSearcher::uniqueSymbol3) {
|
2021-01-11 20:34:51 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
m_search_result_content->enqueue(qMakePair(path, snippets));
|
2021-01-10 15:59:17 +08:00
|
|
|
m_mutex3.unlock();
|
2021-04-26 15:06:47 +08:00
|
|
|
} else {
|
2021-01-10 15:59:17 +08:00
|
|
|
m_mutex3.unlock();
|
2021-01-11 20:49:42 +08:00
|
|
|
return -1;
|
2021-01-10 15:59:17 +08:00
|
|
|
}
|
2021-01-26 16:50:30 +08:00
|
|
|
// searchResult.insert(path,snippets);
|
2021-04-26 15:06:47 +08:00
|
|
|
qDebug() << "path=" << path << ",weight=" << docScoreWeight << ",percent=" << docScorePercent;
|
2021-01-02 17:21:38 +08:00
|
|
|
}
|
|
|
|
// if(!pathTobeDelete->isEmpty())
|
|
|
|
// deleteAllIndex(pathTobeDelete)
|
2021-01-11 20:49:42 +08:00
|
|
|
return 0;
|
2021-01-02 17:21:38 +08:00
|
|
|
}
|
2021-01-08 19:08:24 +08:00
|
|
|
|
2021-04-26 15:06:47 +08:00
|
|
|
bool FileSearcher::isBlocked(QString &path) {
|
2021-01-08 19:08:24 +08:00
|
|
|
QStringList blockList = GlobalSettings::getInstance()->getBlockDirs();
|
2021-04-26 15:06:47 +08:00
|
|
|
for(QString i : blockList) {
|
2021-01-12 16:07:50 +08:00
|
|
|
if(path.startsWith(i.prepend("/")))
|
2021-01-08 19:08:24 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|