Merge pull request #67 from iaom/0110-dev

Modified mode of search thread exit.
This commit is contained in:
张佳萍 2021-01-11 20:58:12 +08:00 committed by GitHub
commit 0f9e4d44a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 23 deletions

View File

@ -120,7 +120,10 @@ int FileSearcher::keywordSearchfile(size_t uniqueSymbol, QString keyword, QStrin
Xapian::MSet result = enquire.get_mset(begin, begin+num); Xapian::MSet result = enquire.get_mset(begin, begin+num);
int resultCount = static_cast<int>(result.get_matches_estimated()); int resultCount = static_cast<int>(result.get_matches_estimated());
qDebug()<< "find results count=" <<resultCount; qDebug()<< "find results count=" <<resultCount;
getResult(uniqueSymbol, result, value); if(result.size() == 0)
return 0;
if(getResult(uniqueSymbol, result, value) == -1)
return -1;
qDebug()<< "--search finish--"; qDebug()<< "--search finish--";
return resultCount; return resultCount;
@ -167,9 +170,12 @@ int FileSearcher::keywordSearchContent(size_t uniqueSymbol, QString keyword, int
//dir result //dir result
Xapian::MSet result = enquire.get_mset(begin, begin+num); Xapian::MSet result = enquire.get_mset(begin, begin+num);
int resultCount = static_cast<int>(result.get_matches_estimated()); int resultCount = static_cast<int>(result.get_matches_estimated());
if(result.size() == 0)
return 0;
qDebug()<< "find results count=" <<resultCount; qDebug()<< "find results count=" <<resultCount;
getContentResult(uniqueSymbol, result, words); if(getContentResult(uniqueSymbol, result, words) == -1)
return -1;
qDebug()<< "--content search finish--"; qDebug()<< "--content search finish--";
return resultCount; return resultCount;
@ -211,14 +217,12 @@ Xapian::Query FileSearcher::creatQueryForContentSearch(QString keyword, Xapian::
} }
QStringList FileSearcher::getResult(size_t uniqueSymbol, Xapian::MSet &result, QString value) int FileSearcher::getResult(size_t uniqueSymbol, Xapian::MSet &result, QString value)
{ {
//QStringList *pathTobeDelete = new QStringList; //QStringList *pathTobeDelete = new QStringList;
//Delete those path doc which is not already exist. //Delete those path doc which is not already exist.
QStringList searchResult = QStringList(); // QStringList searchResult = QStringList();
if(result.size() == 0)
return searchResult;
for (auto it = result.begin(); it != result.end(); ++it) for (auto it = result.begin(); it != result.end(); ++it)
{ {
@ -252,7 +256,7 @@ QStringList FileSearcher::getResult(size_t uniqueSymbol, Xapian::MSet &result, Q
else else
{ {
m_mutex1.unlock(); m_mutex1.unlock();
exit(0); return -1;
} }
break; break;
@ -266,22 +270,22 @@ QStringList FileSearcher::getResult(size_t uniqueSymbol, Xapian::MSet &result, Q
else else
{ {
m_mutex2.unlock(); m_mutex2.unlock();
exit(0); return -1;
} }
break; break;
default: default:
break; break;
} }
searchResult.append(path); // searchResult.append(path);
} }
qDebug()<< "doc="<< path << ",weight=" <<docScoreWeight << ",percent=" << docScorePercent; qDebug()<< "doc="<< path << ",weight=" <<docScoreWeight << ",percent=" << docScorePercent;
} }
// if(!pathTobeDelete->isEmpty()) // if(!pathTobeDelete->isEmpty())
// deleteAllIndex(pathTobeDelete) // deleteAllIndex(pathTobeDelete)
return searchResult; return 0;
} }
QMap<QString,QStringList> FileSearcher::getContentResult(size_t uniqueSymbol, Xapian::MSet &result, std::string &keyWord) int FileSearcher::getContentResult(size_t uniqueSymbol, Xapian::MSet &result, std::string &keyWord)
{ {
//QStringList *pathTobeDelete = new QStringList; //QStringList *pathTobeDelete = new QStringList;
//Delete those path doc which is not already exist. //Delete those path doc which is not already exist.
@ -291,9 +295,7 @@ QMap<QString,QStringList> FileSearcher::getContentResult(size_t uniqueSymbol, Xa
int totalSize = QString::fromStdString(keyWord).size(); int totalSize = QString::fromStdString(keyWord).size();
if(totalSize < 5) if(totalSize < 5)
totalSize = 5; totalSize = 5;
QMap<QString,QStringList> searchResult; // QMap<QString,QStringList> searchResult;
if(result.size() == 0)
return searchResult;
for (auto it = result.begin(); it != result.end(); ++it) for (auto it = result.begin(); it != result.end(); ++it)
{ {
@ -337,17 +339,14 @@ QMap<QString,QStringList> FileSearcher::getContentResult(size_t uniqueSymbol, Xa
else else
{ {
m_mutex3.unlock(); m_mutex3.unlock();
break; return -1;
// exit(0);
} }
// searchResult.insert(path,snippets);
qDebug() << "after";
searchResult.insert(path,snippets);
qDebug()<< "path="<< path << ",weight=" <<docScoreWeight << ",percent=" << docScorePercent; qDebug()<< "path="<< path << ",weight=" <<docScoreWeight << ",percent=" << docScorePercent;
} }
// if(!pathTobeDelete->isEmpty()) // if(!pathTobeDelete->isEmpty())
// deleteAllIndex(pathTobeDelete) // deleteAllIndex(pathTobeDelete)
return searchResult; return 0;
} }
bool FileSearcher::isBlocked(QString &path) bool FileSearcher::isBlocked(QString &path)

View File

@ -48,8 +48,8 @@ private:
Xapian::Query creatQueryForFileSearch(QString keyword, Xapian::Database &db); Xapian::Query creatQueryForFileSearch(QString keyword, Xapian::Database &db);
Xapian::Query creatQueryForContentSearch(QString keyword, Xapian::Database &db); Xapian::Query creatQueryForContentSearch(QString keyword, Xapian::Database &db);
QStringList getResult(size_t uniqueSymbol, Xapian::MSet &result, QString value); int getResult(size_t uniqueSymbol, Xapian::MSet &result, QString value);
QMap<QString,QStringList> getContentResult(size_t uniqueSymbol, Xapian::MSet &result,std::string &keyWord); int getContentResult(size_t uniqueSymbol, Xapian::MSet &result,std::string &keyWord);
bool isBlocked(QString &path); bool isBlocked(QString &path);

View File

@ -85,7 +85,7 @@ void centerToScreen(QWidget* widget) {
int desk_y = desk_rect.height(); int desk_y = desk_rect.height();
int x = widget->width(); int x = widget->width();
int y = widget->height(); int y = widget->height();
// widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top()); widget->move(desk_x / 2 - x / 2 + desk_rect.left(), desk_y / 2 - y / 2 + desk_rect.top());
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])