From 9a7e855d6557c8ead180aa93b6eae4a358a207bb Mon Sep 17 00:00:00 2001 From: "Luke.Ye" Date: Wed, 9 Jul 2025 00:24:20 +0800 Subject: [PATCH] =?UTF-8?q?llm=20opt,=20=E6=94=AF=E6=8C=81=E9=9D=9Emarkdow?= =?UTF-8?q?n=E7=9A=84=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/LLMAppServiceImpl.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/knowledge/base/application/service/LLMAppServiceImpl.java b/src/main/java/com/knowledge/base/application/service/LLMAppServiceImpl.java index 00172cd..fabb15c 100644 --- a/src/main/java/com/knowledge/base/application/service/LLMAppServiceImpl.java +++ b/src/main/java/com/knowledge/base/application/service/LLMAppServiceImpl.java @@ -110,6 +110,7 @@ public class LLMAppServiceImpl implements LLMAppService { log.info("[pinDocsByKeywords] 未查到匹配ES文档,跳过pin操作。"); return Lists.newArrayList(); } + log.info("[pinDocsByKeywords] 已查询到关键词关联的文档。 {}", JSONUtil.toJsonStr(esFilepaths)); // 将当前问题标注为处理中 markQuestionProcessing(question); @@ -122,9 +123,23 @@ public class LLMAppServiceImpl implements LLMAppService { } // 3. 找到需要pin的docPath集合 - List toPinDocs = attachments.stream() - .filter(att -> esFilepaths.stream().anyMatch(f -> att.getUrl().endsWith(f))) - .collect(Collectors.toList()); + List toPinDocs = attachments.stream().filter(att -> { + String url = att.getUrl(); + if (url == null) return false; + // .md 文件 + if (url.endsWith(".md")) { + return esFilepaths.stream().anyMatch(f -> url.endsWith(f)); + } + // 其它文件(如 .pptx、.pdf、.docx等) + int lastSlash = url.lastIndexOf('/'); + String fileName = lastSlash != -1 ? url.substring(lastSlash + 1) : url; + // esFilepaths 里也提取末尾文件名 + return esFilepaths.stream().anyMatch(f -> { + int esLastSlash = f.lastIndexOf('/'); + String esName = esLastSlash != -1 ? f.substring(esLastSlash + 1) : f; + return fileName.equals(esName); + }); + }).collect(Collectors.toList()); // 4. 只unpin之前已pin的文档 attachments.stream()