From 46a01d99b5d15120ada95754c9effbdcb576d31e Mon Sep 17 00:00:00 2001
From: ai_xiaopei <xiaopei@aisim.cn>
Date: Sun, 26 Jul 2026 08:19:23 +0800
Subject: [PATCH] Task 4: add CLI flags for with-content and with-links

---
 internal/search/engine.go |   40 ++++++++++++++++++++++++++++++++--------
 1 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/internal/search/engine.go b/internal/search/engine.go
index 95d7c37..16fa86d 100644
--- a/internal/search/engine.go
+++ b/internal/search/engine.go
@@ -9,18 +9,22 @@
 
 // SearchOptions 搜索选项
 type SearchOptions struct {
-	Expanded []string // 扩展词
-	Symptom  []string // 症状词
-	TopN     int      // 返回前 N 条
+	Expanded    []string // 扩展词
+	Symptom     []string // 症状词
+	TopN        int      // 返回前 N 条
+	WithContent bool     // 返回完整文件内容
+	WithLinks   bool     // 返回关联文档链接
 }
 
 // SearchResult 搜索结果
 type SearchResult struct {
-	ID      int64
-	Path    string
-	Title   string
-	Section string
-	Score   int
+	ID      int64    `json:"id"`
+	Path    string   `json:"path"`
+	Title   string   `json:"title"`
+	Section string   `json:"section"`
+	Score   int      `json:"score"`
+	Content string   `json:"content,omitempty"` // 文件内容(WithContent=true 时填充)
+	Links   []string `json:"links,omitempty"`   // 关联文档路径(WithLinks=true 时填充)
 }
 
 // Search 执行搜索
@@ -76,6 +80,26 @@
 		results = results[:opts.TopN]
 	}
 
+	// 获取内容(如果请求)
+	if opts.WithContent {
+		for i := range results {
+			content, _, _, err := store.GetNodeContent(results[i].ID)
+			if err == nil {
+				results[i].Content = content
+			}
+		}
+	}
+
+	// 获取关联链接(如果请求)
+	if opts.WithLinks {
+		for i := range results {
+			links, err := store.GetNodeLinks(results[i].ID)
+			if err == nil {
+				results[i].Links = links
+			}
+		}
+	}
+
 	return results, nil
 }
 

--
Gitblit v1.9.1