From 8d83d2f828180ec1c2116fd6429692843bb452a3 Mon Sep 17 00:00:00 2001 From: iaom Date: Mon, 5 Dec 2022 15:58:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=A6=96=E6=AC=A1=E7=B4=A2?= =?UTF-8?q?=E5=BC=95=E5=90=8E=EF=BC=8C=E9=87=8D=E5=90=AF=E5=90=8E=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=90=9C=E7=B4=A2=E9=83=A8=E5=88=86=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/index/basic-indexer.cpp | 3 +-- libsearch/index/file-content-indexer.cpp | 2 +- libsearch/index/first-run-indexer.cpp | 2 -- libsearch/index/index-scheduler.cpp | 2 +- libsearch/index/index-updater.cpp | 7 +++++-- libsearch/index/writable-database.cpp | 10 ++++++++-- libsearch/index/writable-database.h | 1 + 7 files changed, 17 insertions(+), 10 deletions(-) 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);