From d00118331bbc14f2c6da5193d7d6226f4f96b7eb Mon Sep 17 00:00:00 2001 From: zhangzihao Date: Tue, 29 Dec 2020 16:41:30 +0800 Subject: [PATCH 1/2] :zap::zap::zap: add multitone words file name search --- file-utils.cpp | 27 +++++++++++++++++++++++++++ file-utils.h | 1 + index/index-generator.cpp | 20 +++++++++++++++++--- index/test-Inotify-Manager.cpp | 12 ++++++------ src/mainwindow.cpp | 21 ++++++++++----------- 5 files changed, 61 insertions(+), 20 deletions(-) diff --git a/file-utils.cpp b/file-utils.cpp index 5a8aa5e..4d52388 100644 --- a/file-utils.cpp +++ b/file-utils.cpp @@ -184,3 +184,30 @@ QString FileUtils::find(const QString &hanzi) return output; } + +void stitchMultiToneWordsDFS(const QString& hanzi, const QString& result, QStringList& resultList){ + if (hanzi.size() == 0){ + resultList.append(result); + return; + } + if (FileUtils::map_chinese2pinyin.contains(hanzi.at(0))){ + for (auto i : FileUtils::map_chinese2pinyin[hanzi.at(0)]){ + stitchMultiToneWordsDFS(hanzi.right(hanzi.size() - 1), result + i, resultList); + } + } + else{ + stitchMultiToneWordsDFS(hanzi.right(hanzi.size() - 1), result + hanzi.at(0), resultList); + } +} + +QStringList FileUtils::findMultiToneWords(const QString& hanzi) +{ +// QStringList* output = new QStringList(); + QStringList output; + QString temp; + QStringList stringList = hanzi.split(""); + + stitchMultiToneWordsDFS(hanzi, temp, output); +// qDebug() << output; + return output; +} diff --git a/file-utils.h b/file-utils.h index 8b37500..af7fe8e 100644 --- a/file-utils.h +++ b/file-utils.h @@ -26,6 +26,7 @@ public: //chinese character to pinyin static QString find(const QString&); + static QStringList findMultiToneWords(const QString&); static void loadHanziTable(const QString&); private: diff --git a/index/index-generator.cpp b/index/index-generator.cpp index d30fea9..e038490 100644 --- a/index/index-generator.cpp +++ b/index/index-generator.cpp @@ -117,8 +117,18 @@ Document IndexGenerator::GenerateDocument(const QVector &list) QString sourcePath = list.at(1); index_text = index_text.replace(".","").replace(""," "); index_text = index_text.simplified(); - QString pinyin_text = FileUtils::find(index_text.replace(".", "")).replace("", " "); - pinyin_text = pinyin_text.simplified(); + //这个应该是写错了 +// QString pinyin_text = FileUtils::find(index_text.replace(".", "")).replace("", " "); + + //不带多音字版 +// QString pinyin_text = FileUtils::find(QString(list.at(0)).replace(".","")).replace("", " ").simplified(); + + //多音字版 + QStringList pintin_text_list = FileUtils::findMultiToneWords(QString(list.at(0)).replace(".","")); + for (QString& i : pintin_text_list){ + i.replace("", " "); + } + QString uniqueterm = QString::fromStdString(FileUtils::makeDocUterm(sourcePath)); // QString uniqueterm1 = QString::fromStdString(QCryptographicHash::hash(sourcePath.toUtf8(),QCryptographicHash::Md5).toStdString()); /*--------------------------------------------------------------------*/ @@ -136,7 +146,11 @@ Document IndexGenerator::GenerateDocument(const QVector &list) doc.addValue(list.at(2)); if(list.at(2) == QString("1")) qDebug()<<"value!!!"<getTargetFileAbsolutePath(); - - /*-------------InotyifyRefact Test Start---------------*/ -// QTime t1 = QTime::currentTime(); -// InotifyManagerRefact* imr = new InotifyManagerRefact("/home"); -// imr->start(); -// QTime t2 = QTime::currentTime(); -// qDebug() << t1; -// qDebug() << t2; - /*-------------InotyifyRefact Test End-----------------*/ +// FileUtils::findMultiToneWords("翟康宁test"); + /*-------------Inotify Test Start---------------*/ + QTime t1 = QTime::currentTime(); + InotifyManagerRefact* im = new InotifyManagerRefact("/home"); + im->Traverse(); + QTime t2 = QTime::currentTime(); + qDebug() << t1; + qDebug() << t2; + im->start(); + /*-------------Inotify Test End-----------------*/ this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); this->setAttribute(Qt::WA_TranslucentBackground, true); From 7308c98090844a9dbd82ded46a83bedcd85c9c15 Mon Sep 17 00:00:00 2001 From: zhangzihao Date: Tue, 29 Dec 2020 19:30:48 +0800 Subject: [PATCH 2/2] add the first letter search --- file-utils.cpp | 13 +++++++------ index/index-generator.cpp | 7 ++++--- src/mainwindow.cpp | 14 +++++++------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/file-utils.cpp b/file-utils.cpp index 4d52388..14b8797 100644 --- a/file-utils.cpp +++ b/file-utils.cpp @@ -185,18 +185,19 @@ QString FileUtils::find(const QString &hanzi) return output; } -void stitchMultiToneWordsDFS(const QString& hanzi, const QString& result, QStringList& resultList){ +void stitchMultiToneWordsDFS(const QString& hanzi, const QString& resultAllPinYin, const QString& resultFirst, QStringList& resultList){ if (hanzi.size() == 0){ - resultList.append(result); + resultList.append(resultAllPinYin); + resultList.append(resultFirst); return; } if (FileUtils::map_chinese2pinyin.contains(hanzi.at(0))){ for (auto i : FileUtils::map_chinese2pinyin[hanzi.at(0)]){ - stitchMultiToneWordsDFS(hanzi.right(hanzi.size() - 1), result + i, resultList); + stitchMultiToneWordsDFS(hanzi.right(hanzi.size() - 1), resultAllPinYin + i, resultFirst + i.at(0), resultList); } } else{ - stitchMultiToneWordsDFS(hanzi.right(hanzi.size() - 1), result + hanzi.at(0), resultList); + stitchMultiToneWordsDFS(hanzi.right(hanzi.size() - 1), resultAllPinYin + hanzi.at(0), resultFirst + hanzi.at(0), resultList); } } @@ -204,10 +205,10 @@ QStringList FileUtils::findMultiToneWords(const QString& hanzi) { // QStringList* output = new QStringList(); QStringList output; - QString temp; + QString tempAllPinYin, tempFirst; QStringList stringList = hanzi.split(""); - stitchMultiToneWordsDFS(hanzi, temp, output); + stitchMultiToneWordsDFS(hanzi, tempAllPinYin, tempFirst, output); // qDebug() << output; return output; } diff --git a/index/index-generator.cpp b/index/index-generator.cpp index e038490..0e29ebc 100644 --- a/index/index-generator.cpp +++ b/index/index-generator.cpp @@ -124,8 +124,9 @@ Document IndexGenerator::GenerateDocument(const QVector &list) // QString pinyin_text = FileUtils::find(QString(list.at(0)).replace(".","")).replace("", " ").simplified(); //多音字版 - QStringList pintin_text_list = FileUtils::findMultiToneWords(QString(list.at(0)).replace(".","")); - for (QString& i : pintin_text_list){ + //现加入首字母 + QStringList pinyin_text_list = FileUtils::findMultiToneWords(QString(list.at(0)).replace(".","")); + for (QString& i : pinyin_text_list){ i.replace("", " "); } @@ -148,7 +149,7 @@ Document IndexGenerator::GenerateDocument(const QVector &list) qDebug()<<"value!!!"<Traverse(); - QTime t2 = QTime::currentTime(); - qDebug() << t1; - qDebug() << t2; - im->start(); +// QTime t1 = QTime::currentTime(); +// InotifyManagerRefact* im = new InotifyManagerRefact("/home"); +// im->Traverse(); +// QTime t2 = QTime::currentTime(); +// qDebug() << t1; +// qDebug() << t2; +// im->start(); /*-------------Inotify Test End-----------------*/ this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);