diff --git a/libsearch/index/basic-indexer.cpp b/libsearch/index/basic-indexer.cpp index 17631bd..c6b69f3 100644 --- a/libsearch/index/basic-indexer.cpp +++ b/libsearch/index/basic-indexer.cpp @@ -29,13 +29,12 @@ BasicIndexer::BasicIndexer(const QString& filePath): m_filePath(filePath) bool BasicIndexer::index() { QFileInfo info = QFileInfo(m_filePath); - //添加数据 m_document.setData(m_filePath); //唯一term m_document.setUniqueTerm(FileUtils::makeDocUterm(m_filePath)); //上层文件夹term,用于在上层文件夹删除时删除自己 - m_document.addTerm(FileUtils::makeDocUterm(m_filePath.section("/", 0, -2, QString::SectionIncludeLeadingSep))); + m_document.addTerm("PARENTTERM" + FileUtils::makeDocUterm(m_filePath.section("/", 0, -2, QString::SectionIncludeLeadingSep))); //1-目录, 0-文件 m_document.addValue(1, QString((info.isDir() && (!info.isSymLink())) ? "1" : "0")); //修改时间 diff --git a/libsearch/index/file-content-indexer.cpp b/libsearch/index/file-content-indexer.cpp index 368696e..81628ac 100644 --- a/libsearch/index/file-content-indexer.cpp +++ b/libsearch/index/file-content-indexer.cpp @@ -51,7 +51,7 @@ bool fileContentIndexer::index() term.shrink_to_fit(); m_document.setUniqueTerm(FileUtils::makeDocUterm(m_filePath)); - m_document.addTerm(FileUtils::makeDocUterm(m_filePath.section("/", 0, -2, QString::SectionIncludeLeadingSep))); + m_document.addTerm("PARENTTERM" + FileUtils::makeDocUterm(m_filePath.section("/", 0, -2, QString::SectionIncludeLeadingSep))); m_document.addValue(1, m_filePath); m_document.addValue(2, suffix); m_document.setIndexTime(info.lastModified().toString("yyyyMMddHHmmsszzz")); diff --git a/libsearch/index/first-run-indexer.cpp b/libsearch/index/first-run-indexer.cpp index 35d5ce2..9b0aa41 100644 --- a/libsearch/index/first-run-indexer.cpp +++ b/libsearch/index/first-run-indexer.cpp @@ -141,7 +141,6 @@ void FirstRunIndexer::basicIndex() qDebug() << indexTimes.size() << "documents need remove."; for(std::string uniqueTerm : indexTimes.keys()) { basicDb.removeDocument(uniqueTerm); - basicDb.setMetaData(uniqueTerm, ""); } basicDb.commit(); } @@ -231,7 +230,6 @@ void FirstRunIndexer::contentIndex() qDebug() << indexTimes.size() << "documents need remove"; for(std::string uniqueTerm : indexTimes.keys()) { contentDb.removeDocument(uniqueTerm); - contentDb.setMetaData(uniqueTerm, ""); } contentDb.commit(); } diff --git a/libsearch/index/index-scheduler.cpp b/libsearch/index/index-scheduler.cpp index 180f565..6fd2b51 100644 --- a/libsearch/index/index-scheduler.cpp +++ b/libsearch/index/index-scheduler.cpp @@ -133,7 +133,7 @@ FirstRunIndexer::Targets IndexScheduler::checkAndRebuild() && m_config->isFileIndexEnable()) { qDebug() << "Content database need rebuild"; target |= FirstRunIndexer::Target::Content; - m_statusRecorder->setStatus(INDEX_DATABASE_STATE_KEY, IndexStatusRecorder::State::Initializing); + m_statusRecorder->setStatus(CONTENT_INDEX_DATABASE_STATE_KEY, IndexStatusRecorder::State::Initializing); } startIndexJob(mode, target); return target; diff --git a/libsearch/index/index-updater.cpp b/libsearch/index/index-updater.cpp index eff61d2..27cf5f3 100644 --- a/libsearch/index/index-updater.cpp +++ b/libsearch/index/index-updater.cpp @@ -45,6 +45,9 @@ void IndexUpdater::UpdateIndex() if(file.shouldRemoveIndex()) { qDebug() << "| remove:" <delete_document(uniqueTerm);) + DATABASE_TRY(m_xpDatabase->delete_document(uniqueTerm); + m_xpDatabase->set_metadata(uniqueTerm, "");) +} + +void WritableDatabase::removeChildrenDocument(const QString &path) +{ + DATABASE_TRY(m_xpDatabase->delete_document("PARENTTERM" + FileUtils::makeDocUterm(path));) } void WritableDatabase::setMetaData(const QString &key, const QString &value) diff --git a/libsearch/index/writable-database.h b/libsearch/index/writable-database.h index 1f13b38..851a732 100644 --- a/libsearch/index/writable-database.h +++ b/libsearch/index/writable-database.h @@ -46,6 +46,7 @@ public: void addDocument(const Document& doc); void removeDocument(const QString& path); void removeDocument(const std::string uniqueTerm); + void removeChildrenDocument(const QString& path); void setMetaData(const QString& key, const QString& value); void setMetaData(const std::string& key, const std::string& value); const std::string getMetaData(const std::string &key);