feat(ai-index):文件修改时使用更新接口更新索引
This commit is contained in:
parent
4d20ad9b94
commit
6442166431
|
@ -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
|
|
@ -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();
|
||||
|
|
|
@ -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)) {
|
||||
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)) {
|
||||
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);
|
||||
|
||||
}
|
|
@ -245,6 +245,8 @@ void IndexUpdater::updateAiIndex()
|
|||
qDebug() << "| remove:" <<file.path();
|
||||
indexer.deleteFileIndex({file.path()});
|
||||
}
|
||||
} else if(file.isModified()) {
|
||||
update(&AiIndexer::update);
|
||||
} else if(FileIndexerConfig::getInstance()->aiIndexFileTarget()[suffix] && !file.isDir()) {
|
||||
update(&AiIndexer::addTextFileIndex);
|
||||
} else if (FileIndexerConfig::getInstance()->aiIndexImageTarget()[suffix] && !file.isDir()) {
|
||||
|
|
Loading…
Reference in New Issue