fix:Sets polyphonic and English questions when searching

This commit is contained in:
“sunfengsheng” 2021-03-29 10:17:26 +08:00
parent 0d2785eb49
commit c76c501c18
2 changed files with 61 additions and 46 deletions

View File

@ -33,7 +33,6 @@ SettingsMatch::SettingsMatch(QObject *parent) : QObject(parent)
*/ */
QStringList SettingsMatch::startMatchApp(const QString &source){ QStringList SettingsMatch::startMatchApp(const QString &source){
m_sourceText=source; m_sourceText=source;
// qDebug()<<m_sourceText;
QStringList settingList=matching(); QStringList settingList=matching();
return settingList; return settingList;
} }
@ -43,9 +42,8 @@ QStringList SettingsMatch::startMatchApp(const QString &source){
* xml文件内容读到内存 * xml文件内容读到内存
*/ */
void SettingsMatch::xmlElement(){ void SettingsMatch::xmlElement(){
QString pinyinIndex;
QString ChineseIndex; QString ChineseIndex;
QString EnglishIndex;
QFile file(QString::fromLocal8Bit("/usr/share/ukui-control-center/shell/res/search.xml")); QFile file(QString::fromLocal8Bit("/usr/share/ukui-control-center/shell/res/search.xml"));
if (!file.open(QIODevice::ReadOnly)){ if (!file.open(QIODevice::ReadOnly)){
return; return;
@ -60,36 +58,27 @@ void SettingsMatch::xmlElement(){
QDomElement element=node.toElement(); QDomElement element=node.toElement();
QString key=element.attribute("name");; QString key=element.attribute("name");;
m_chine_searchResult=m_chine_searchList.value(key); m_chine_searchResult=m_chine_searchList.value(key);
m_pinyin_searchResult=m_pinyin_searchList.value(key); m_English_searchResult=m_English_searchList.value(key);
QDomNodeList list=element.childNodes(); QDomNodeList list=element.childNodes();
for(int i=0;i<list.count();++i){ for(int i=0;i<list.count();++i){
QDomNode n=list.at(i); QDomNode n=list.at(i);
if(n.nodeName()==QString::fromLocal8Bit("pinyinPlugin")){
pinyinIndex=n.toElement().text();
}
if(n.nodeName()==QString::fromLocal8Bit("pinyinfunc")){
pinyinIndex+=QString::fromLocal8Bit("/")+n.toElement().text();
m_pinyin_searchResult.append(pinyinIndex);
}
if(n.nodeName()==QString::fromLocal8Bit("ChinesePlugin")){ if(n.nodeName()==QString::fromLocal8Bit("ChinesePlugin")){
ChineseIndex=n.toElement().text(); ChineseIndex=n.toElement().text();
} }
if(n.nodeName()==QString::fromLocal8Bit("ChineseFunc")){ if(n.nodeName()==QString::fromLocal8Bit("ChineseFunc")){
ChineseIndex+=QString::fromLocal8Bit("/")+n.toElement().text(); ChineseIndex+=QString::fromLocal8Bit("/")+n.toElement().text();
m_chine_searchResult.append(ChineseIndex);
m_chine_searchResult.append(ChineseIndex); }
if(n.nodeName()==QString::fromLocal8Bit("EnglishFunc")){
EnglishIndex=QString::fromLocal8Bit("/")+n.toElement().text();
m_English_searchResult.append(EnglishIndex);
} }
} }
m_pinyin_searchList.insert(key,m_pinyin_searchResult);
m_chine_searchList.insert(key,m_chine_searchResult); m_chine_searchList.insert(key,m_chine_searchResult);
m_English_searchList.insert(key,m_English_searchResult);
node=node.nextSibling(); node=node.nextSibling();
} }
file.close(); file.close();
// qDebug()<<pinyin_searchlist;
// qDebug()<<chine_searchlist;
} }
/** /**
@ -101,35 +90,61 @@ QStringList SettingsMatch::matching(){
QStringList returnresult; QStringList returnresult;
QStringList regmatch; QStringList regmatch;
QString key; QString key;
QStringList pinyinlist;
QMap<QString, QStringList>::const_iterator i; QMap<QString, QStringList>::const_iterator i;
for(i=m_chine_searchList.constBegin();i!=m_chine_searchList.constEnd();++i){ QLocale ql;
regmatch=*i; if(ql.language()==QLocale::Chinese){
key=i.key(); for(i=m_chine_searchList.constBegin();i!=m_chine_searchList.constEnd();++i){
// qDebug()<<key; regmatch=*i;
for(int t=0; t<regmatch.size();t++) key=i.key();
{ for(int t=0; t<regmatch.size();t++)
if(m_sourceText=="/")
continue;
QString str =regmatch.at(t);
if(str.contains(m_sourceText))
{ {
str=key+"/"+str; if(m_sourceText=="/")
returnresult.append(str);//中文名 continue;
continue; QString str =regmatch.at(t);
pinyinlist=FileUtils::findMultiToneWords(str);
if(str.contains(m_sourceText))
{
str=key+"/"+str;
returnresult.append(str);//中文名
continue;
}
for(int i = 0;i<pinyinlist.size()/2;i++){
str =regmatch.at(t);
QString shouzimu=pinyinlist.at(2*i+1); // 中文转首字母
if(shouzimu.contains(m_sourceText,Qt::CaseInsensitive)){
str=key+"/"+str;
returnresult.append(str);
break;
}
if(m_sourceText.size()<2)
break;
QString pinyin=pinyinlist.at(2*i);// 中文转拼音
if(pinyin.contains(m_sourceText,Qt::CaseInsensitive)){
str=key+"/"+str;
returnresult.append(str);
break;
}
}
}
}
}
if(ql.language()==QLocale::English){
for(i=m_English_searchList.constBegin();i!=m_English_searchList.constEnd();++i){
regmatch=*i;
key=i.key();
for(int t=0; t<regmatch.size();t++)
{
if(m_sourceText=="/")
continue;
QString str =regmatch.at(t);
if(str.contains(m_sourceText,Qt::CaseInsensitive)){
str=key+"/"+str;
returnresult.append(str);
}
} }
QString shouzimu=FileUtils::findMultiToneWords(str).at(1);// 中文转首字母
if(shouzimu.contains(m_sourceText,Qt::CaseInsensitive)){
str=key+"/"+str;
returnresult.append(str);
continue;
}
QString pinyin=FileUtils::findMultiToneWords(str).at(0);// 中文转拼音
if(pinyin.contains(m_sourceText,Qt::CaseInsensitive)){
str=key+"/"+str;
returnresult.append(str);
}
} }
} }
// qDebug()<<returnresult;
return returnresult; return returnresult;
} }

View File

@ -42,10 +42,10 @@ private:
QStringList matching(); QStringList matching();
private: private:
QMap<QString,QStringList> m_pinyin_searchList;
QMap<QString,QStringList> m_chine_searchList; QMap<QString,QStringList> m_chine_searchList;
QStringList m_pinyin_searchResult; QMap<QString,QStringList> m_English_searchList;
QStringList m_chine_searchResult; QStringList m_chine_searchResult;
QStringList m_English_searchResult;
QString m_sourceText; QString m_sourceText;
}; };