From 64421664315787216d4fb2b195490e88c120e010 Mon Sep 17 00:00:00 2001 From: iaom Date: Sun, 28 Apr 2024 10:10:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(ai-index):=E6=96=87=E4=BB=B6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=97=B6=E4=BD=BF=E7=94=A8=E6=9B=B4=E6=96=B0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=9B=B4=E6=96=B0=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libsearch/index/ai-indexer.cpp | 14 ++++++++++++++ libsearch/index/ai-indexer.h | 1 + libsearch/index/batch-indexer.cpp | 22 +++++++++++++++++----- libsearch/index/index-updater.cpp | 2 ++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/libsearch/index/ai-indexer.cpp b/libsearch/index/ai-indexer.cpp index 8abed40..cd6056a 100644 --- a/libsearch/index/ai-indexer.cpp +++ b/libsearch/index/ai-indexer.cpp @@ -151,4 +151,18 @@ bool AiIndexer::getAllIndexedFiles(QJsonObject &object) return false; } +bool AiIndexer::update(const QJsonArray &object) +{ + if(!AiIndexerPrivate::m_sessionValid) { + return false; + } + DataManagementResult result = data_management_update_files_content(AiIndexerPrivate::m_session, QJsonDocument(object).toJson().data()); + if(result != DataManagementResult::DATA_MANAGEMENT_SUCCESS) { + qWarning() << "Fail to call data_management_update_files_content, input: " << QJsonDocument(object).toJson().data() + << "result:" << result; + return false; + } + return true; +} + } // UkuiSearch \ No newline at end of file diff --git a/libsearch/index/ai-indexer.h b/libsearch/index/ai-indexer.h index b825f1d..f665c26 100644 --- a/libsearch/index/ai-indexer.h +++ b/libsearch/index/ai-indexer.h @@ -36,6 +36,7 @@ public: bool addImageFileIndex(const QJsonArray &object); bool deleteFileIndex(const QStringList &files); bool getAllIndexedFiles(QJsonObject &object); + bool update(const QJsonArray &object); private: bool destroySession(); diff --git a/libsearch/index/batch-indexer.cpp b/libsearch/index/batch-indexer.cpp index d215c97..195be23 100644 --- a/libsearch/index/batch-indexer.cpp +++ b/libsearch/index/batch-indexer.cpp @@ -409,6 +409,7 @@ void BatchIndexer::aiIndex() } QJsonObject filesNeedAiIndex; QJsonObject imagesNeedAiIndex; + QJsonObject filesNeedUpdate; QFileInfo info; if (m_mode == WorkMode::Add) { for (const QString &path: m_cache) { @@ -441,18 +442,28 @@ void BatchIndexer::aiIndex() } QString type; if (FileIndexerConfig::getInstance()->aiIndexFileTarget()[info.suffix()]) { - if(indexTimes.value(path).toInt() != info.lastModified().toSecsSinceEpoch()) { + int modifiedTime = indexTimes.value(path).toInt(0); + if(modifiedTime != info.lastModified().toSecsSinceEpoch()) { if(indexer.checkFileSupported(path, type)) { - filesNeedAiIndex.insert(path, type); + if(modifiedTime) { + filesNeedUpdate.insert(path, type); //修改时间不为空时执行更新 + } else { + filesNeedAiIndex.insert(path, type); + } indexTimes.remove(path); } } else { indexTimes.remove(path); } } else if (FileIndexerConfig::getInstance()->aiIndexImageTarget()[info.suffix()]) { - if(indexTimes.value(path).toInt() != info.lastModified().toSecsSinceEpoch()) { + int modifiedTime = indexTimes.value(path).toInt(0); + if(modifiedTime != info.lastModified().toSecsSinceEpoch()) { if(indexer.checkFileSupported(path, type)) { - imagesNeedAiIndex.insert(path, type); + if(modifiedTime) { + filesNeedUpdate.insert(path, type); //修改时间不为空时执行更新 + } else { + imagesNeedAiIndex.insert(path, type); + } indexTimes.remove(path); } } else { @@ -467,7 +478,7 @@ void BatchIndexer::aiIndex() } } - uint allSize = filesNeedAiIndex.size() + imagesNeedAiIndex.size(); + uint allSize = filesNeedAiIndex.size() + imagesNeedAiIndex.size() + filesNeedUpdate.size(); qDebug() << allSize << "files need ai index."; Q_EMIT progress(IndexType::Ai, allSize, 0); @@ -504,5 +515,6 @@ void BatchIndexer::aiIndex() }; creatIndex(&AiIndexer::addImageFileIndex, imagesNeedAiIndex); creatIndex(&AiIndexer::addTextFileIndex, filesNeedAiIndex); + creatIndex(&AiIndexer::update, filesNeedUpdate); } \ No newline at end of file diff --git a/libsearch/index/index-updater.cpp b/libsearch/index/index-updater.cpp index 2b67257..8adbca9 100644 --- a/libsearch/index/index-updater.cpp +++ b/libsearch/index/index-updater.cpp @@ -245,6 +245,8 @@ void IndexUpdater::updateAiIndex() qDebug() << "| remove:" <aiIndexFileTarget()[suffix] && !file.isDir()) { update(&AiIndexer::addTextFileIndex); } else if (FileIndexerConfig::getInstance()->aiIndexImageTarget()[suffix] && !file.isDir()) {