From 9e33822bdd30bf552f79ad12fd87eb13d037611b Mon Sep 17 00:00:00 2001 From: "Luke.Ye" Date: Mon, 1 Sep 2025 06:19:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=A7=E7=BB=AD=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E6=97=A0=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/infrastructure/config/DynamicConfig.java | 3 +++ .../north/controller/FileQueryController.java | 7 +++++-- .../north/controller/FileWriteController.java | 9 +++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/knowledge/base/infrastructure/config/DynamicConfig.java b/src/main/java/com/knowledge/base/infrastructure/config/DynamicConfig.java index 4cc2741..0061ba3 100644 --- a/src/main/java/com/knowledge/base/infrastructure/config/DynamicConfig.java +++ b/src/main/java/com/knowledge/base/infrastructure/config/DynamicConfig.java @@ -72,6 +72,9 @@ public class DynamicConfig { @Value("${thread.pool.monitor.enabled:true}") private boolean enableThreadPoolMonitor; + @Value("${es.show.context.length:150}") + private String esShowContextLen; + // 监听配置刷新事件,主动刷新线程池监控 @EventListener public void onRefresh(RefreshScopeRefreshedEvent event) { diff --git a/src/main/java/com/knowledge/base/infrastructure/north/controller/FileQueryController.java b/src/main/java/com/knowledge/base/infrastructure/north/controller/FileQueryController.java index 209a6fb..5ea4051 100644 --- a/src/main/java/com/knowledge/base/infrastructure/north/controller/FileQueryController.java +++ b/src/main/java/com/knowledge/base/infrastructure/north/controller/FileQueryController.java @@ -11,6 +11,7 @@ import com.knowledge.base.domain.common.model.PageResult; import com.knowledge.base.domain.doc.model.FileEsField; import com.knowledge.base.infrastructure.cache.iface.FileCacheService; import com.knowledge.base.infrastructure.config.ConstantConfig; +import com.knowledge.base.infrastructure.config.DynamicConfig; import com.knowledge.base.infrastructure.north.dto.SearchReq; import com.knowledge.base.infrastructure.north.dto.doc.OSRecordDTO; import com.knowledge.base.infrastructure.north.dto.user.UserDTO; @@ -44,6 +45,8 @@ public class FileQueryController { private final FileElasticsearchGateway esGateway; + private final DynamicConfig dynamicConfig; + @Autowired private FileCacheService fileCacheService; @@ -171,7 +174,7 @@ public class FileQueryController { result.put("url", source.get(FileEsField.URL)); String content = (String) source.get(FileEsField.CONTENT); - String summary = extractMultiSnippet(content, keywords, 50); + String summary = extractMultiSnippet(content, keywords, Integer.parseInt(dynamicConfig.getEsShowContextLen().trim())); result.put("summary", summary); results.add(result); @@ -205,7 +208,7 @@ public class FileQueryController { } if (matchedSnippets.isEmpty()) { - return content.length() <= 100 ? content : content.substring(0, 100) + "..."; + return content.length() <= contextLength ? content : content.substring(0, contextLength) + "..."; } return String.join(" ... ", matchedSnippets); diff --git a/src/main/java/com/knowledge/base/infrastructure/north/controller/FileWriteController.java b/src/main/java/com/knowledge/base/infrastructure/north/controller/FileWriteController.java index 4cbed3c..09dccbe 100644 --- a/src/main/java/com/knowledge/base/infrastructure/north/controller/FileWriteController.java +++ b/src/main/java/com/knowledge/base/infrastructure/north/controller/FileWriteController.java @@ -145,8 +145,9 @@ public class FileWriteController { byte[] fileBytes = file.getBytes(); logger.info("[uploadFolderToOS] 已上传至对象存储: {}", originalName); - ThreadPoolUtil.execute(() -> - handleAsyncRecord(finalToken, bucket, originFileNameWithSuffix, suffix, s3FullPath, finalUrl, fileBytes, searchable) + ThreadPoolUtil.execute(() -> { + handleAsyncRecord(finalToken, bucket, originFileNameWithSuffix, suffix, s3FullPath, finalUrl, fileBytes, searchable); + } ); } @@ -155,7 +156,7 @@ public class FileWriteController { "count", filePathMap.size(), "files", filePathMap )); - } catch (Exception e) { + } catch (Throwable e) { logger.error("上传失败", e); return ResponseEntity.status(500).body("上传失败: " + e.getMessage()); } @@ -246,7 +247,7 @@ public class FileWriteController { logger.info("本地文件信息已保存并导入ES: localRelaPath = {}, ESImportRes = {}", localRelaFilePath, res); } - } catch (Exception e) { + } catch (Throwable e) { logger.error("异步写入失败: {}", originFileNameWithSuffix, e); } }