diff --git a/libsearch/index/construct-document.cpp b/libsearch/index/construct-document.cpp index 5c0797a..134c50e 100644 --- a/libsearch/index/construct-document.cpp +++ b/libsearch/index/construct-document.cpp @@ -45,13 +45,18 @@ void ConstructDocumentForPath::run() // qDebug()<<_doc_list_path->size(); QString index_text = m_list.at(0); QString sourcePath = m_list.at(1); + Document doc; //多音字版 //现加入首字母 QStringList pinyin_text_list = FileUtils::findMultiToneWords(QString(m_list.at(0)).replace(".","")); - for (QString& i : pinyin_text_list){ - i.replace("", " "); - i = i.simplified(); + if(!pinyin_text_list.isEmpty()) + { + for (QString& i : pinyin_text_list){ + i.replace("", " "); + i = i.simplified(); + } + doc.setIndexText(pinyin_text_list); } QString uniqueterm = QString::fromStdString(FileUtils::makeDocUterm(sourcePath)); @@ -62,7 +67,7 @@ void ConstructDocumentForPath::run() // qDebug() << "ConstructDocumentForPath -- uniqueterm: " << uniqueterm; // qDebug() << "ConstructDocumentForPath -- upTerm: " << upTerm; - Document doc; + doc.setData(sourcePath); doc.setUniqueTerm(uniqueterm); doc.addTerm(upTerm); @@ -70,7 +75,6 @@ void ConstructDocumentForPath::run() /* QStringList temp; // temp.append(index_text); temp.append(pinyin_text_list)*/; - doc.setIndexText(pinyin_text_list); int postingCount = 0; while(postingCount < index_text.size()) { diff --git a/libsearch/index/index-generator.cpp b/libsearch/index/index-generator.cpp index 5924c0d..7a5aacf 100644 --- a/libsearch/index/index-generator.cpp +++ b/libsearch/index/index-generator.cpp @@ -200,9 +200,11 @@ void IndexGenerator::insertIntoDatabase(Document& doc) for(auto i : doc.getIndexText()){ m_indexer.index_text(i.toStdString()); } + qDebug()<<"insert m_database_path:"<replace_document(doc.getUniqueTerm(),document); -// qDebug()<<"replace doc docid="<(innerId); + qDebug()<<"replace doc docid="<(innerId); // qDebug()<< "--index finish--"; return; } diff --git a/libsearch/index/inotify-index.cpp b/libsearch/index/inotify-index.cpp index 7628e2d..216e4de 100644 --- a/libsearch/index/inotify-index.cpp +++ b/libsearch/index/inotify-index.cpp @@ -163,13 +163,9 @@ void InotifyIndex::eventProcess(const char* buf, ssize_t tmp){ qDebug() << QString(currentPath[event->wd] + '/' + event->name); // switch (event->mask) { if (event->mask & IN_CREATE){ - qDebug() << "IN_CREATE"; - if (event->mask & IN_ISDIR){ - AddWatch(currentPath[event->wd] + '/' + event->name); - setPath(currentPath[event->wd] + '/' + event->name); - Traverse(); - } + //Create top dir first, traverse it last. + qDebug() << "IN_CREATE"; /*--------------------------------*/ // IndexGenerator::getInstance()->creatAllIndex(QQueue>(QVector() << fileInfo.fileName() << fileInfo.absoluteFilePath() << QString(fileInfo.isDir() ? "1" : "0"))); indexQueue->enqueue(QVector() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0")); @@ -183,6 +179,12 @@ void InotifyIndex::eventProcess(const char* buf, ssize_t tmp){ break; } } + + if (event->mask & IN_ISDIR){ + AddWatch(currentPath[event->wd] + '/' + event->name); + setPath(currentPath[event->wd] + '/' + event->name); + Traverse(); + } goto next; } @@ -223,9 +225,7 @@ void InotifyIndex::eventProcess(const char* buf, ssize_t tmp){ if (event->mask & IN_ISDIR){ RemoveWatch(currentPath[event->wd] + '/' + event->name); // IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name)); - AddWatch(currentPath[event->wd] + '/' + event->name); - setPath(currentPath[event->wd] + '/' + event->name); - Traverse(); + indexQueue->enqueue(QVector() << QString(event->name) << QString(currentPath[event->wd] + '/' + event->name) << QString((event->mask & IN_ISDIR) ? "1" : "0")); IndexGenerator::getInstance()->creatAllIndex(indexQueue); @@ -238,6 +238,11 @@ void InotifyIndex::eventProcess(const char* buf, ssize_t tmp){ break; } } + + AddWatch(currentPath[event->wd] + '/' + event->name); + setPath(currentPath[event->wd] + '/' + event->name); + Traverse(); + } else { IndexGenerator::getInstance()->deleteAllIndex(new QStringList(currentPath[event->wd] + '/' + event->name));