From b554c303193aa5d22af5f8a4b91430077113e6db Mon Sep 17 00:00:00 2001
From: ax_rd <ax_rd@aisim.cn>
Date: Thu, 03 Sep 2026 13:21:36 +0800
Subject: [PATCH] fix: search 长 CJK 词 bigram 展开统一下沉(ExpandCJKKeywords 共享 + textScore 按 Expanded 档计权 + graph query 边 provenance 填充)

---
 cmd/rebuild.go |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/cmd/rebuild.go b/cmd/rebuild.go
index a93794f..47684dd 100644
--- a/cmd/rebuild.go
+++ b/cmd/rebuild.go
@@ -26,7 +26,7 @@
 	fmt.Fprintf(os.Stderr, "扫描到 %d 个文件\n", len(files))
 
 	// 构建图
-	g := graph.BuildGraph(files)
+	g, unresolved := graph.BuildGraph(files)
 
 	// 写入节点,并记录 BuildGraph ID -> SQLite ID 的映射
 	idMap := make(map[int64]int64) // BuildGraph ID -> SQLite ID
@@ -52,10 +52,11 @@
 			continue
 		}
 		edge := &graph.Edge{
-			FromNode: fromID,
-			ToNode:   toID,
-			Relation: e.Relation,
-			Label:    e.Label,
+			FromNode:   fromID,
+			ToNode:     toID,
+			Relation:   e.Relation,
+			Label:      e.Label,
+			Provenance: e.Provenance,
 		}
 		if err := store.InsertEdge(edge); err != nil {
 			return fmt.Errorf("插入边失败: %w", err)
@@ -63,6 +64,17 @@
 		actualEdgeCount++
 	}
 
+	// 写入悬空链接(BuildGraph 内部 ID 映射为 SQLite ID)
+	for _, u := range unresolved {
+		fromID, ok := idMap[u.FromNode]
+		if !ok {
+			continue
+		}
+		if err := store.InsertUnresolved(fromID, u.LinkText, u.NameTail); err != nil {
+			return fmt.Errorf("写入悬空链接失败 [%s]: %w", u.LinkText, err)
+		}
+	}
+
 	// 创建并填充 FTS5 索引
 	if err := store.CreateFTS(); err != nil {
 		return fmt.Errorf("创建 FTS 索引失败: %w", err)

--
Gitblit v1.10.0