File tree 3 files changed +101
-0
lines changed
3 files changed +101
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "log"
5
+ "time"
6
+
7
+ "github.com/google/gops/agent"
8
+ )
9
+
10
+ func main () {
11
+ if err := agent .Listen (nil ); err != nil {
12
+ log .Fatal (err )
13
+ }
14
+ time .Sleep (time .Hour )
15
+ }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "log"
6
+ "net/http"
7
+ "runtime"
8
+ "time"
9
+
10
+ _ "net/http/pprof"
11
+
12
+ "github.com/gorilla/handlers"
13
+ _ "github.com/mkevac/debugcharts"
14
+ )
15
+
16
+ func dummyCPUUsage () {
17
+ var a uint64
18
+ var t = time .Now ()
19
+ for {
20
+ t = time .Now ()
21
+ a += uint64 (t .Unix ())
22
+ }
23
+ }
24
+
25
+ func dummyAllocations () {
26
+ var d []uint64
27
+
28
+ for {
29
+ for i := 0 ; i < 2 * 1024 * 1024 ; i ++ {
30
+ d = append (d , 42 )
31
+ }
32
+ time .Sleep (time .Second * 10 )
33
+ fmt .Println (len (d ))
34
+ d = make ([]uint64 , 0 )
35
+ runtime .GC ()
36
+ time .Sleep (time .Second * 10 )
37
+ }
38
+ }
39
+
40
+ func main () {
41
+ go dummyAllocations ()
42
+ go dummyCPUUsage ()
43
+ go func () {
44
+ log .Fatal (http .ListenAndServe (":8080" , handlers .CompressHandler (http .DefaultServeMux )))
45
+ }()
46
+ log .Printf ("you can now open http://localhost:8080/debug/charts/ in your browser" )
47
+ select {}
48
+ }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "log"
5
+
6
+ "github.com/go-ego/riot"
7
+ "github.com/go-ego/riot/types"
8
+ )
9
+
10
+ var (
11
+ // searcher 是协程安全的
12
+ searcher = riot.Engine {}
13
+ )
14
+
15
+ func main () {
16
+ // 初始化
17
+ searcher .Init (types.EngineOpts {
18
+ Using : 3 ,
19
+ SegmenterDict : "zh" ,
20
+ // SegmenterDict: "your gopath"+"/src/github.com/go-ego/riot/data/dict/dictionary.txt",
21
+ })
22
+ defer searcher .Close ()
23
+
24
+ text := "此次百度收购将成中国互联网最大并购"
25
+ text1 := "百度宣布拟全资收购91无线业务"
26
+ text2 := "百度是中国最大的搜索引擎"
27
+
28
+ // 将文档加入索引,docId 从1开始
29
+ searcher .IndexDoc (1 , types.DocIndexData {Content : text })
30
+ searcher .IndexDoc (2 , types.DocIndexData {Content : text1 }, false )
31
+ searcher .IndexDoc (3 , types.DocIndexData {Content : text2 }, true )
32
+
33
+ // 等待索引刷新完毕
34
+ searcher .FlushIndex ()
35
+
36
+ // 搜索输出格式见 types.SearchResp 结构体
37
+ log .Print (searcher .Search (types.SearchReq {Text : "百度中国" }))
38
+ }
You can’t perform that action at this time.
0 commit comments