ai_xiaopei
2026-07-25 7445005745523d430a3cd22c3208cce2f383f1ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package index
 
import (
    "path/filepath"
    "testing"
 
    "github.com/aisim/kb-cli/internal/graph"
)
 
func TestFTSSearch(t *testing.T) {
    tmpDir := t.TempDir()
    dbPath := filepath.Join(tmpDir, "test.db")
 
    store, err := Open(dbPath)
    if err != nil {
        t.Fatalf("Open failed: %v", err)
    }
    defer store.Close()
 
    // 插入测试数据
    store.InsertNode(&graph.Node{
        ID:      1,
        Path:    "FAQ/充装类/001-test.md",
        Title:   "充装问题排查",
        Section: "FAQ",
        Tags:    []string{"充装"},
        Content: "关于智能枪充装问题的排查方法",
    })
    store.InsertNode(&graph.Node{
        ID:      2,
        Path:    "知识/002-config.md",
        Title:   "充装规格配置",
        Section: "知识",
        Tags:    []string{"配置"},
        Content: "充装规格配置说明",
    })
 
    // 创建 FTS
    if err := store.CreateFTS(); err != nil {
        t.Fatalf("CreateFTS failed: %v", err)
    }
    if err := store.PopulateFTS(); err != nil {
        t.Fatalf("PopulateFTS failed: %v", err)
    }
 
    // 搜索 - FTS5 对中文按字符 tokenize,"充装" 两个节点都包含
    results, err := store.FTSSearch([]string{"充装"}, 10)
    if err != nil {
        t.Fatalf("FTSSearch failed: %v", err)
    }
    if len(results) < 1 {
        t.Errorf("result count = %d, want >= 1", len(results))
    }
}