Modified file search interface.

This commit is contained in:
zhangpengfei 2020-12-26 21:11:17 +08:00
parent 67f9e4f1ef
commit 9a6b2f607e
6 changed files with 112 additions and 65 deletions

View File

@ -1,13 +1,15 @@
#include "file-searcher.h"
#include <QFileInfo>
#include <QDebug>
FileSearcher::FileSearcher(QObject *parent) : QObject(parent)
{
}
void FileSearcher::onKeywordSearch(QString keyword)
void FileSearcher::onKeywordSearch(QString keyword, int begin, int num)
{
QStringList searchResult;
QVector<QStringList> searchResult;
try
{
qDebug()<<"--search start--";
@ -19,14 +21,14 @@ void FileSearcher::onKeywordSearch(QString keyword)
qp.set_database(db);
auto userInput = keyword;
std::string queryStr = indexText.replace(""," ").toStdString();
std::string queryStr = keyword.replace(""," ").toStdString();
// std::string s =db.get_spelling_suggestion(queryStr,10);
// qDebug()<<"spelling_suggestion!"<<QString::fromStdString(s);
qDebug()<<"queryStr!"<<QString::fromStdString(queryStr);
//Creat a query
Xapian::Query queryPhrase = qp.parse_query(queryStr,Xapian::QueryParser::FLAG_PHRASE);
vector<Xapian::Query> v;
std::vector<Xapian::Query> v;
for(int i=0;i<userInput.size();i++)
{
v.push_back(Xapian::Query(QString(userInput.at(i)).toStdString()));
@ -36,17 +38,53 @@ void FileSearcher::onKeywordSearch(QString keyword)
Xapian::Query queryNear =Xapian::Query(Xapian::Query::OP_NEAR, v.begin(), v.end());
Xapian::Query query = Xapian::Query(Xapian::Query::OP_AND,queryNear,queryPhrase);
//1- dir 2-file
unsigned slot = 1;
std::string value = "1";
Xapian::Query queryValue1 = Xapian::Query(Xapian::Query::OP_VALUE_GE,slot,value);
value = "0";
Xapian::Query queryValue0 = Xapian::Query(Xapian::Query::OP_VALUE_LE,1,value);
Xapian::Query queryDir = Xapian::Query(Xapian::Query::OP_AND,query,queryValue1);
Xapian::Query queryFile = Xapian::Query(Xapian::Query::OP_AND,query,queryValue0);
qDebug()<<QString::fromStdString(query.get_description());
enquire.set_query(query);
Xapian::MSet result = enquire.get_mset(0, 9999);
qDebug()<< "find results count=" <<static_cast<int>(result.get_matches_estimated());
enquire.set_query(queryDir);
//dir result
Xapian::MSet result = enquire.get_mset(begin, begin+num);
qDebug()<< "find dir results count=" <<static_cast<int>(result.get_matches_estimated());
searchResult.append(getResult(result));
enquire.set_query(queryFile);
//file result
result = enquire.get_mset(begin, begin+num);
qDebug()<< "find file results count=" <<static_cast<int>(result.get_matches_estimated());
searchResult.append(getResult(result));
qDebug()<< "--search finish--";
}
catch(const Xapian::Error &e)
{
qDebug() <<QString::fromStdString(e.get_description());
return;
}
Q_EMIT this->result(searchResult);
return;
}
QStringList FileSearcher::getResult(Xapian::MSet &result)
{
//QStringList *pathTobeDelete = new QStringList;
//Delete those path doc which is not already exist.
//get search result
for (auto it = result.begin(); it != result.end(); ++it) {
QStringList searchResult = QStringList();
if(result.size() == 0)
return searchResult;
for (auto it = result.begin(); it != result.end(); ++it)
{
Xapian::Document doc = it.get_document();
qDebug()<<"value!!!!"<<QString::fromStdString(doc.get_value(1));
std::string data = doc.get_data();
Xapian::weight docScoreWeight = it.get_weight();
Xapian::percent docScorePercent = it.get_percent();
@ -64,18 +102,7 @@ void FileSearcher::onKeywordSearch(QString keyword)
qDebug()<< "doc="<< QString::fromStdString(data) << ",weight=" <<docScoreWeight << ",percent=" << docScorePercent;
}
// //Delete those path doc which is not already exist.
// if(!pathTobeDelete->isEmpty())
// deleteAllIndex(pathTobeDelete);
qDebug()<< "--search finish--";
}
catch(const Xapian::Error &e)
{
qDebug() <<QString::fromStdString(e.get_description());
return;
}
Q_EMIT this->result(searchResult);
return;
// deleteAllIndex(pathTobeDelete)
return searchResult;
}

View File

@ -3,6 +3,8 @@
#include <QObject>
#include <xapian.h>
#include <QStandardPaths>
#include <QVector>
#define INDEX_PATH (QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/.config/org.ukui/index_data").toStdString()
@ -13,12 +15,12 @@ public:
explicit FileSearcher(QObject *parent = nullptr);
public Q_SLOTS:
void onKeywordSearch(QString keyword);
void onKeywordSearch(QString keyword, int begin, int num);
Q_SIGNALS:
void result(QStringList resultList);
void result(QVector<QStringList> resultV);
private:
QStringList getResult(Xapian::MSet &result);
};
#endif // FILESEARCHER_H

View File

@ -134,8 +134,10 @@ Document IndexGenerator::GenerateDocument(const QVector<QString> &list)
doc.setData(sourcePath);
doc.setUniqueTerm(uniqueterm);
doc.addValue(list.at(2));
if(list.at(2) == QString("1"))
qDebug()<<"value!!!"<<list.at(2);
doc.setIndexText(QStringList()<<index_text<<pinyin_text);
doc.setIndexText(QStringList()<<index_text);
// doc.setIndexText(QStringList()<<index_text);
return doc;
}
@ -169,7 +171,7 @@ QStringList IndexGenerator::IndexSearch(QString indexText)
qDebug()<<"queryStr!"<<QString::fromStdString(queryStr);
//Creat a query
Xapian::Query queryPhrase = qp.parse_query(queryStr,Xapian::QueryParser::FLAG_PHRASE);
vector<Xapian::Query> v;
std::vector<Xapian::Query> v;
for(int i=0;i<userInput.size();i++)
{
v.push_back(Xapian::Query(QString(userInput.at(i)).toStdString()));

View File

@ -40,7 +40,9 @@ InotifyManagerRefact::~InotifyManagerRefact(){
}
void InotifyManagerRefact::DoSomething(const QFileInfo& fileInfo){
this->mlm->AddMessage(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(bool((fileInfo.isDir()))));
this->mlm->AddMessage(QVector<QString>() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir()?"1":"0"));
// if(QString(bool((fileInfo.isDir()))) == QString("1"))
// qDebug()<<"bool((fileInfo.isDir())"<<QString(fileInfo.isDir());
// this->mlm->AddMessage(QVector<QString>() << "PLog" << "/home/zpf/baidunetdisk/PLog" << "1");
if(fileInfo.isDir()){
this->AddWatch(fileInfo.absoluteFilePath());

View File

@ -47,6 +47,14 @@ int main(int argc, char *argv[])
{
//load chinese character and pinyin file to a Map
FileUtils::loadHanziTable("://index/pinyinWithoutTone.txt");
/*-------------InotyifyRefact Test Start---------------*/
QTime t1 = QTime::currentTime();
InotifyManagerRefact* imr = new InotifyManagerRefact("/home");
imr->start();
QTime t2 = QTime::currentTime();
qDebug() << t1;
qDebug() << t2;
/*-------------InotyifyRefact Test End-----------------*/
qRegisterMetaType<QVector<QStringList>>("QVector<QStringList>");

View File

@ -34,6 +34,7 @@
#include "index-generator.h"
//#include "inotify-manager.h"
#include "inotify.h"
#include "file-searcher.h"
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
/**
@ -46,17 +47,6 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int tran
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
/*-------------InotyifyRefact Test Start---------------*/
QTime t1 = QTime::currentTime();
InotifyManagerRefact* imr = new InotifyManagerRefact("/home");
imr->start();
QTime t2 = QTime::currentTime();
qDebug() << t1;
qDebug() << t2;
/*-------------InotyifyRefact Test End-----------------*/
this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
this->setAttribute(Qt::WA_TranslucentBackground, true);
this->setAutoFillBackground(false);
@ -228,31 +218,47 @@ void MainWindow::primaryScreenChangedSlot(QScreen *screen)
* @param searchcontent
*/
void MainWindow::searchContent(QString searchcontent){
QVector<int> types;
QVector<QStringList> lists;
// QVector<int> types;
// QVector<QStringList> lists;
//测试用数据
QStringList list;
list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop";
QStringList list2;
list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx";
QStringList list3;
list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题";
types.append(SearchItem::SearchType::Apps);
types.append(SearchItem::SearchType::Settings);
types.append(SearchItem::SearchType::Files);
// QStringList list;
// list<<"/usr/share/applications/peony.desktop"<<"/usr/share/applications/ukui-control-center.desktop"<<"/usr/share/applications/wps-office-pdf.desktop";
// QStringList list2;
// list2<<"/home/zjp/下载/搜索结果.png"<<"/home/zjp/下载/显示不全.mp4"<<"/home/zjp/下载/dmesg.log"<<"/home/zjp/下载/WiFi_AP选择.docx";
// QStringList list3;
// list3<<"About/关于/计算机属性"<<"Area/语言和地区/货币单位"<<"Datetime/时间和日期/手动更改时间"<<"Theme/主题/图标主题";
// types.append(SearchItem::SearchType::Apps);
// types.append(SearchItem::SearchType::Settings);
// types.append(SearchItem::SearchType::Files);
lists.append(list);
lists.append(list3);
lists.append(list2);
// lists.append(list);
// lists.append(list3);
// lists.append(list2);
//文件搜索
FileSearcher *searcher = new FileSearcher();
connect(searcher,&FileSearcher::result,[=](QVector<QStringList> resultV){
QStringList list1 = resultV.at(0);
// QStringList list2 = resultV.at(1);
QVector<QStringList> lists;
lists.append(list1);
QVector<int> types;
types.append(SearchItem::SearchType::Files);
// types.append(SearchItem::SearchType::Files);
m_contentFrame->refreshSearchList(types, lists);
});
searcher->onKeywordSearch(searchcontent,0,10);
// QStringList res = IndexGenerator::IndexSearch(searchcontent);
// types.append(SearchItem::SearchType::Files);
// lists.append(res);
//将搜索结果加入列表
m_contentFrame->refreshSearchList(types, lists);
// m_contentFrame->refreshSearchList(types, lists);
}
//使用GSetting获取当前窗口应该使用的透明度