解决全局搜索中遍历搜索不能搜索到顶层文件夹的问题

This commit is contained in:
iaom 2023-04-21 11:22:41 +08:00
parent 80320ab9f2
commit 37e3de3cee
2 changed files with 32 additions and 28 deletions

View File

@ -507,6 +507,7 @@ void DirectSearch::run() {
if (!underBlock) { if (!underBlock) {
blockList.append(DirWatcher::getDirWatcher()->blackListOfDir(path)); blockList.append(DirWatcher::getDirWatcher()->blackListOfDir(path));
bfs.enqueue(path); bfs.enqueue(path);
match(QFileInfo(path));
} }
} }
if (bfs.isEmpty()) { if (bfs.isEmpty()) {
@ -540,34 +541,36 @@ void DirectSearch::run() {
} }
bfs.enqueue(i.absoluteFilePath()); bfs.enqueue(i.absoluteFilePath());
} }
if(i.fileName().contains(m_keyword, Qt::CaseInsensitive)) { match(i);
// qWarning() << i.fileName() << m_keyword; }
// if(m_searchResult->length() > 49) }
// return; }
if((i.isDir() && m_value == DIR_SEARCH_VALUE)) {
SearchPluginIface::ResultInfo ri; void DirectSearch::match(const QFileInfo &info)
if(SearchManager::creatResultInfo(ri,i.absoluteFilePath())) { {
SearchManager::m_mutexDir.lock(); if(info.fileName().contains(m_keyword, Qt::CaseInsensitive)) {
if(m_uniqueSymbol == SearchManager::uniqueSymbolDir) { if((info.isDir() && m_value == DIR_SEARCH_VALUE)) {
m_searchResult->enqueue(ri); SearchPluginIface::ResultInfo ri;
SearchManager::m_mutexDir.unlock(); if(SearchManager::creatResultInfo(ri,info.absoluteFilePath())) {
} else { SearchManager::m_mutexDir.lock();
SearchManager::m_mutexDir.unlock(); if(m_uniqueSymbol == SearchManager::uniqueSymbolDir) {
return; m_searchResult->enqueue(ri);
} SearchManager::m_mutexDir.unlock();
} } else {
} else if (i.isFile() && m_value == FILE_SEARCH_VALUE) { SearchManager::m_mutexDir.unlock();
SearchPluginIface::ResultInfo ri; return;
if(SearchManager::creatResultInfo(ri,i.absoluteFilePath())) { }
SearchManager::m_mutexFile.lock(); }
if(m_uniqueSymbol == SearchManager::uniqueSymbolFile) { } else if (info.isFile() && m_value == FILE_SEARCH_VALUE) {
m_searchResult->enqueue(ri); SearchPluginIface::ResultInfo ri;
SearchManager::m_mutexFile.unlock(); if(SearchManager::creatResultInfo(ri,info.absoluteFilePath())) {
} else { SearchManager::m_mutexFile.lock();
SearchManager::m_mutexFile.unlock(); if(m_uniqueSymbol == SearchManager::uniqueSymbolFile) {
return; m_searchResult->enqueue(ri);
} SearchManager::m_mutexFile.unlock();
} } else {
SearchManager::m_mutexFile.unlock();
return;
} }
} }
} }

View File

@ -161,6 +161,7 @@ public:
protected: protected:
void run(); void run();
private: private:
void match(const QFileInfo& info);
QString m_keyword; QString m_keyword;
DataQueue<SearchPluginIface::ResultInfo>* m_searchResult = nullptr; DataQueue<SearchPluginIface::ResultInfo>* m_searchResult = nullptr;
size_t m_uniqueSymbol; size_t m_uniqueSymbol;