| | |
| | | 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 |
| | |
| | | ToNode: toID, |
| | | Relation: e.Relation, |
| | | Label: e.Label, |
| | | Provenance: e.Provenance, |
| | | } |
| | | if err := store.InsertEdge(edge); err != nil { |
| | | return fmt.Errorf("插入边失败: %w", err) |
| | |
| | | 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) |