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