Merge pull request #25 from MouseZhangZh/zzh-search
⚡⚡⚡ add multitone words file name search
This commit is contained in:
commit
c34d0dbdce
|
@ -184,3 +184,31 @@ QString FileUtils::find(const QString &hanzi)
|
|||
|
||||
return output;
|
||||
}
|
||||
|
||||
void stitchMultiToneWordsDFS(const QString& hanzi, const QString& resultAllPinYin, const QString& resultFirst, QStringList& resultList){
|
||||
if (hanzi.size() == 0){
|
||||
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), resultAllPinYin + i, resultFirst + i.at(0), resultList);
|
||||
}
|
||||
}
|
||||
else{
|
||||
stitchMultiToneWordsDFS(hanzi.right(hanzi.size() - 1), resultAllPinYin + hanzi.at(0), resultFirst + hanzi.at(0), resultList);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList FileUtils::findMultiToneWords(const QString& hanzi)
|
||||
{
|
||||
// QStringList* output = new QStringList();
|
||||
QStringList output;
|
||||
QString tempAllPinYin, tempFirst;
|
||||
QStringList stringList = hanzi.split("");
|
||||
|
||||
stitchMultiToneWordsDFS(hanzi, tempAllPinYin, tempFirst, output);
|
||||
// qDebug() << output;
|
||||
return output;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -117,8 +117,19 @@ Document IndexGenerator::GenerateDocument(const QVector<QString> &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 pinyin_text_list = FileUtils::findMultiToneWords(QString(list.at(0)).replace(".",""));
|
||||
for (QString& i : pinyin_text_list){
|
||||
i.replace("", " ");
|
||||
}
|
||||
|
||||
QString uniqueterm = QString::fromStdString(FileUtils::makeDocUterm(sourcePath));
|
||||
// QString uniqueterm1 = QString::fromStdString(QCryptographicHash::hash(sourcePath.toUtf8(),QCryptographicHash::Md5).toStdString());
|
||||
/*--------------------------------------------------------------------*/
|
||||
|
@ -136,7 +147,11 @@ Document IndexGenerator::GenerateDocument(const QVector<QString> &list)
|
|||
doc.addValue(list.at(2));
|
||||
if(list.at(2) == QString("1"))
|
||||
qDebug()<<"value!!!"<<list.at(2);
|
||||
doc.setIndexText(QStringList()<<index_text<<pinyin_text);
|
||||
QStringList temp;
|
||||
temp.append(index_text);
|
||||
temp.append(pinyin_text_list);
|
||||
doc.setIndexText(temp);
|
||||
// doc.setIndexText(QStringList()<<index_text<<pinyin_text);
|
||||
// doc.setIndexText(QStringList()<<index_text);
|
||||
return doc;
|
||||
|
||||
|
|
|
@ -18,12 +18,12 @@ void testTraverse(void){
|
|||
/*-------------Inotify Test End-----------------*/
|
||||
|
||||
/*-------------PinyinSearch Test Start---------------*/
|
||||
QTime t1 = QTime::currentTime();
|
||||
QString test("test");
|
||||
qDebug() << IndexGenerator::IndexSearch(test);
|
||||
QTime t2 = QTime::currentTime();
|
||||
qDebug() << t1;
|
||||
qDebug() << t2;
|
||||
// QTime t1 = QTime::currentTime();
|
||||
// QString test("test");
|
||||
// qDebug() << IndexGenerator::IndexSearch(test);
|
||||
// QTime t2 = QTime::currentTime();
|
||||
// qDebug() << t1;
|
||||
// qDebug() << t2;
|
||||
/*-------------PinyinSearch Test End-----------------*/
|
||||
|
||||
/*-------------InotyifyRefact Test Start---------------*/
|
||||
|
|
|
@ -50,17 +50,16 @@ extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int tran
|
|||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent)
|
||||
{
|
||||
FileTypeFilter* ftf = new FileTypeFilter("/home");
|
||||
ftf->getTargetFileAbsolutePath();
|
||||
|
||||
/*-------------InotyifyRefact Test Start---------------*/
|
||||
// FileUtils::findMultiToneWords("翟康宁test");
|
||||
/*-------------Inotify Test Start---------------*/
|
||||
// QTime t1 = QTime::currentTime();
|
||||
// InotifyManagerRefact* imr = new InotifyManagerRefact("/home");
|
||||
// imr->start();
|
||||
// InotifyManagerRefact* im = new InotifyManagerRefact("/home");
|
||||
// im->Traverse();
|
||||
// QTime t2 = QTime::currentTime();
|
||||
// qDebug() << t1;
|
||||
// qDebug() << t2;
|
||||
/*-------------InotyifyRefact Test End-----------------*/
|
||||
// im->start();
|
||||
/*-------------Inotify Test End-----------------*/
|
||||
|
||||
this->setWindowFlags(Qt::CustomizeWindowHint | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint);
|
||||
this->setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
|
|
Loading…
Reference in New Issue