perf(settingsearch):修改设置搜索的匹配策略.

This commit is contained in:
JunjieBai 2023-10-08 16:48:24 +08:00
parent ea2bbbdfb5
commit 524a43787b
2 changed files with 43 additions and 16 deletions

View File

@ -382,6 +382,7 @@ void SettingsMatch::startSearch(QString &keyword, size_t uniqueSymbol, DataQueue
return;
}
//根据searchMap的对应关系匹配dataMap中的数据信息
QStringList thirdLvKeys;
for (auto i = m_searchMap.constBegin(); i != m_searchMap.constEnd(); ++i) {
QMap<QString, QStringList> regMatch = *i;
QString moduleName = i.key();
@ -389,12 +390,31 @@ void SettingsMatch::startSearch(QString &keyword, size_t uniqueSymbol, DataQueue
//匹配二级菜单信息
QString pluginName = t.key();
QString keyOfSecondLv =QString("%1/%2").arg(moduleName, pluginName);
matchDataMap(keyOfSecondLv, keyword, uniqueSymbol, searchResult);
bool isSecondLv = matchDataMap(keyOfSecondLv, keyword);
//匹配对应三级菜单信息
for (QString funcName: t.value()) {
for (const QString& funcName: t.value()) {
QString keyOfThirdLv = keyOfSecondLv + QString("/%1").arg(funcName);
matchDataMap(keyOfThirdLv, keyword, uniqueSymbol, searchResult);
if (isSecondLv) {
SearchPluginIface::ResultInfo resultInfo;
resultInfo.type = 0;
createResultInfo(resultInfo, m_dataMap.value(keyOfThirdLv), keyOfThirdLv);
if (!enqueueResultInfo(resultInfo, uniqueSymbol, searchResult)) {
return;
}
} else if (matchDataMap(keyOfThirdLv, keyword)) {
thirdLvKeys.append(keyOfThirdLv);
}
}
}
}
//单独处理三级
for (const QString& key : thirdLvKeys) {
SearchPluginIface::ResultInfo resultInfo;
resultInfo.type = 0;
createResultInfo(resultInfo, m_dataMap.value(key), key);
if (!enqueueResultInfo(resultInfo, uniqueSymbol, searchResult)) {
return;
}
}
}
@ -409,8 +429,9 @@ void SettingsMatch::removeItem(QVariantMap replyMap)
this->parsingArgsOfDbus(replyMap, HandleType::Delete);
}
void SettingsMatch::matchDataMap(QString &key, QString &keyword, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult)
bool SettingsMatch::matchDataMap(QString &key, QString &keyword)
{
bool res(false);
SearchPluginIface::ResultInfo resultInfo;
resultInfo.type = 0;
for (int counter = 0; counter < m_dataMap.value(key).size(); ++counter) {
@ -420,19 +441,11 @@ void SettingsMatch::matchDataMap(QString &key, QString &keyword, size_t uniqueSy
continue;
}
if (data.contains(keyword, Qt::CaseInsensitive)) {
createResultInfo(resultInfo, m_dataMap.value(key), key);
//判断是否为同一次搜索
SettingsSearchPlugin::m_mutex.lock();
if (uniqueSymbol == SettingsSearchPlugin::m_uniqueSymbolForSettings) {
searchResult->enqueue(resultInfo);
SettingsSearchPlugin::m_mutex.unlock();
res = true;
break;
} else {
SettingsSearchPlugin::m_mutex.unlock();
return;
}
}
}
return res;
}
void SettingsMatch::createResultInfo(SearchPluginIface::ResultInfo &resultInfo, const QStringList &itemInfo, const QString &path)
@ -448,3 +461,16 @@ void SettingsMatch::createResultInfo(SearchPluginIface::ResultInfo &resultInfo,
resultInfo.icon = FileUtils::getSettingIcon();
resultInfo.actionKey = path.section("/", 1, 1);
}
bool SettingsMatch::enqueueResultInfo(SearchPluginIface::ResultInfo &resultInfo, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult) {
bool res(false);
SettingsSearchPlugin::m_mutex.lock();
if (uniqueSymbol == SettingsSearchPlugin::m_uniqueSymbolForSettings) {
res = true;
searchResult->enqueue(resultInfo);
SettingsSearchPlugin::m_mutex.unlock();
} else {
SettingsSearchPlugin::m_mutex.unlock();
}
return res;
}

View File

@ -109,8 +109,9 @@ private:
void matchNodes(QDomNode node);
//search
void matchDataMap(QString &key, QString &keyword, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult);
bool matchDataMap(QString &key, QString &keyword);
void createResultInfo(SearchPluginIface::ResultInfo &resultInfo, const QStringList &itemInfo, const QString &path);
bool enqueueResultInfo(SearchPluginIface::ResultInfo &resultInfo, size_t uniqueSymbol, DataQueue<SearchPluginIface::ResultInfo> *searchResult);
QMap<QString, QMap<QString, QStringList>> m_searchMap;
QMap<QString, QStringList> m_dataMap;
QDBusInterface *m_interface = nullptr;