UkuiSearchTask增加一个setMatchAllIfNoKeyword()方法,如果设置为true则在未添加关键词时匹配所有文件名并返回
This commit is contained in:
parent
39709ebc3a
commit
67ebd40a70
|
@ -36,6 +36,7 @@ public:
|
||||||
QStringList m_searchDirs;
|
QStringList m_searchDirs;
|
||||||
QStringList m_FileLabels;
|
QStringList m_FileLabels;
|
||||||
bool m_recurse = true;
|
bool m_recurse = true;
|
||||||
|
bool m_matchAllIfNoKeyword = false;
|
||||||
bool m_activeKeywordSegmentation = false;
|
bool m_activeKeywordSegmentation = false;
|
||||||
bool m_onlySearchFile = false;
|
bool m_onlySearchFile = false;
|
||||||
bool m_onlySearchDir = false;
|
bool m_onlySearchDir = false;
|
||||||
|
@ -127,6 +128,11 @@ void SearchController::addKeyword(const QString &keyword)
|
||||||
d->m_keywords.append(keyword);
|
d->m_keywords.append(keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SearchController::setMatchAllIfNoKeyword(bool matchAll)
|
||||||
|
{
|
||||||
|
d->m_matchAllIfNoKeyword = matchAll;
|
||||||
|
}
|
||||||
|
|
||||||
size_t SearchController::getCurrentSearchId()
|
size_t SearchController::getCurrentSearchId()
|
||||||
{
|
{
|
||||||
d->m_searchIdMutex.lock();
|
d->m_searchIdMutex.lock();
|
||||||
|
@ -208,6 +214,11 @@ QStringList SearchController::getKeyword()
|
||||||
return d->m_keywords;
|
return d->m_keywords;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SearchController::getMatchAllIfNoKeyword()
|
||||||
|
{
|
||||||
|
return d->m_matchAllIfNoKeyword;
|
||||||
|
}
|
||||||
|
|
||||||
bool SearchController::isKeywordSegmentationActived()
|
bool SearchController::isKeywordSegmentationActived()
|
||||||
{
|
{
|
||||||
return d->m_activeKeywordSegmentation;
|
return d->m_activeKeywordSegmentation;
|
||||||
|
|
|
@ -47,6 +47,7 @@ public:
|
||||||
void addSearchDir(const QString &path);
|
void addSearchDir(const QString &path);
|
||||||
void setRecurse(bool recurse = true);
|
void setRecurse(bool recurse = true);
|
||||||
void addKeyword(const QString &keyword);
|
void addKeyword(const QString &keyword);
|
||||||
|
void setMatchAllIfNoKeyword(bool matchAll);
|
||||||
void setActiveKeywordSegmentation(bool active);
|
void setActiveKeywordSegmentation(bool active);
|
||||||
void addFileLabel(const QString &label);
|
void addFileLabel(const QString &label);
|
||||||
void setOnlySearchFile(bool onlySearchFile);
|
void setOnlySearchFile(bool onlySearchFile);
|
||||||
|
@ -68,6 +69,7 @@ public:
|
||||||
QStringList getSearchDir();
|
QStringList getSearchDir();
|
||||||
bool isRecurse();
|
bool isRecurse();
|
||||||
QStringList getKeyword();
|
QStringList getKeyword();
|
||||||
|
bool getMatchAllIfNoKeyword();
|
||||||
bool isKeywordSegmentationActived();
|
bool isKeywordSegmentationActived();
|
||||||
QStringList getFileLabel();
|
QStringList getFileLabel();
|
||||||
bool isSearchFileOnly();
|
bool isSearchFileOnly();
|
||||||
|
|
|
@ -176,6 +176,9 @@ Xapian::Query FileSearchWorker::creatQueryForFileSearch() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Xapian::Query> queries;
|
std::vector<Xapian::Query> queries;
|
||||||
|
if (m_searchController->getKeyword().isEmpty() && m_searchController->getMatchAllIfNoKeyword()) {
|
||||||
|
queries.emplace_back(Xapian::Query::MatchAll);
|
||||||
|
} else {
|
||||||
for (QString &keyword : m_searchController->getKeyword()) {
|
for (QString &keyword : m_searchController->getKeyword()) {
|
||||||
if (!keyword.isEmpty()) {
|
if (!keyword.isEmpty()) {
|
||||||
std::vector<Xapian::Query> queryOfKeyword;
|
std::vector<Xapian::Query> queryOfKeyword;
|
||||||
|
@ -192,6 +195,7 @@ Xapian::Query FileSearchWorker::creatQueryForFileSearch() {
|
||||||
queries.emplace_back(Xapian::Query::OP_PHRASE, queryOfKeyword.begin(), queryOfKeyword.end());
|
queries.emplace_back(Xapian::Query::OP_PHRASE, queryOfKeyword.begin(), queryOfKeyword.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {Xapian::Query::OP_AND, {Xapian::Query::OP_AND, queries.begin(), queries.end()}, fileOrDir};
|
return {Xapian::Query::OP_AND, {Xapian::Query::OP_AND, queries.begin(), queries.end()}, fileOrDir};
|
||||||
}
|
}
|
||||||
|
@ -303,6 +307,9 @@ bool FileSearchWorker::directSearch()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool matched = false;
|
bool matched = false;
|
||||||
|
if (m_searchController->getKeyword().isEmpty() && m_searchController->getMatchAllIfNoKeyword()) {
|
||||||
|
matched = true;
|
||||||
|
} else {
|
||||||
//同时包含几个key为成功匹配
|
//同时包含几个key为成功匹配
|
||||||
for (const QString &keyword: m_searchController->getKeyword()) {
|
for (const QString &keyword: m_searchController->getKeyword()) {
|
||||||
if (!keyword.isEmpty()) {
|
if (!keyword.isEmpty()) {
|
||||||
|
@ -313,6 +320,7 @@ bool FileSearchWorker::directSearch()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (matched && !m_labels.empty()) {
|
if (matched && !m_labels.empty()) {
|
||||||
matched = FileSearchFilter::checkFileLabel(fileInfo.absoluteFilePath(), m_labels);
|
matched = FileSearchFilter::checkFileLabel(fileInfo.absoluteFilePath(), m_labels);
|
||||||
|
|
|
@ -63,6 +63,11 @@ void UkuiSearchTask::addKeyword(const QString &keyword)
|
||||||
d->m_searchCotroller.addKeyword(keyword);
|
d->m_searchCotroller.addKeyword(keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UkuiSearchTask::setMatchAllIfNoKeyword(bool matchAll)
|
||||||
|
{
|
||||||
|
d->m_searchCotroller.setMatchAllIfNoKeyword(matchAll);
|
||||||
|
}
|
||||||
|
|
||||||
void UkuiSearchTask::addFileLabel(const QString &label)
|
void UkuiSearchTask::addFileLabel(const QString &label)
|
||||||
{
|
{
|
||||||
d->m_searchCotroller.addFileLabel(label);
|
d->m_searchCotroller.addFileLabel(label);
|
||||||
|
|
|
@ -35,6 +35,12 @@ public:
|
||||||
void addSearchDir(const QString &path);
|
void addSearchDir(const QString &path);
|
||||||
void setRecurse(bool recurse = true);
|
void setRecurse(bool recurse = true);
|
||||||
void addKeyword(const QString &keyword);
|
void addKeyword(const QString &keyword);
|
||||||
|
/**
|
||||||
|
* 是否在未添加关键词的情况下进行所有文件名匹配
|
||||||
|
* @brief setMatchAllIfNoKeyword
|
||||||
|
* @param matchAll
|
||||||
|
*/
|
||||||
|
void setMatchAllIfNoKeyword(bool matchAll);
|
||||||
void addFileLabel(const QString &label);
|
void addFileLabel(const QString &label);
|
||||||
void setOnlySearchFile(bool onlySearchFile);
|
void setOnlySearchFile(bool onlySearchFile);
|
||||||
void setOnlySearchDir(bool onlySearchDir);
|
void setOnlySearchDir(bool onlySearchDir);
|
||||||
|
|
Loading…
Reference in New Issue