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()) {