From d51140e0336c6554036c70b2ae20735382b8428d Mon Sep 17 00:00:00 2001 From: wizardchen Date: Wed, 7 Jan 2026 15:37:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9C=A8=E6=90=9C=E7=B4=A2=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E4=B8=AD=E6=89=B9=E9=87=8F=E8=A1=A5=E5=85=85=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/application/service/knowledge.go | 38 +++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/internal/application/service/knowledge.go b/internal/application/service/knowledge.go index f1cb59b0..47a2513d 100644 --- a/internal/application/service/knowledge.go +++ b/internal/application/service/knowledge.go @@ -4192,6 +4192,44 @@ func (s *knowledgeService) SearchFAQEntries(ctx context.Context, entries = entries[:req.MatchCount] } + // 批量查询TagName并补充到结果中 + if len(entries) > 0 { + // 收集所有需要查询的TagID + tagIDs := make([]string, 0) + tagIDSet := make(map[string]struct{}) + for _, entry := range entries { + if entry.TagID != "" { + if _, exists := tagIDSet[entry.TagID]; !exists { + tagIDs = append(tagIDs, entry.TagID) + tagIDSet[entry.TagID] = struct{}{} + } + } + } + + // 批量查询标签 + if len(tagIDs) > 0 { + tags, err := s.tagRepo.GetByIDs(ctx, tenantID, tagIDs) + if err != nil { + logger.Warnf(ctx, "Failed to batch query tags: %v", err) + } else { + // 构建TagID到TagName的映射 + tagNameMap := make(map[string]string) + for _, tag := range tags { + tagNameMap[tag.ID] = tag.Name + } + + // 补充TagName + for _, entry := range entries { + if entry.TagID != "" { + if tagName, exists := tagNameMap[entry.TagID]; exists { + entry.TagName = tagName + } + } + } + } + } + } + return entries, nil }