-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhistogram.go
132 lines (120 loc) · 2.65 KB
/
histogram.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
type TermCount struct {
Term string
Count uint64
}
type sortedTermCounts []TermCount
func (s sortedTermCounts) Len() int {
return len(s)
}
func (s sortedTermCounts) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s sortedTermCounts) Less(i, j int) bool {
return s[i].Count < s[j].Count
}
var (
histogramCmd = app.Command("histogram", "generate indexed terms histogram")
)
func histogramFn(cfg *Config) error {
/*
index, err := OpenOfferIndex(cfg.Index())
if err != nil {
return err
}
terms := map[string]uint64{}
rows := index.DumpAll()
var failed error
for item := range rows {
if failed != nil {
continue
}
switch item.(type) {
case error:
failed = item.(error)
case *upsidedown.TermFrequencyRow:
row := item.(*upsidedown.TermFrequencyRow)
terms[string(row.Term())] += row.Freq()
}
}
if failed != nil {
return failed
}
counts := make([]TermCount, 0, len(terms))
for k, v := range terms {
counts = append(counts, TermCount{
Term: k,
Count: v,
})
}
sort.Sort(sortedTermCounts(counts))
for _, t := range counts {
fmt.Println(t.Term, t.Count)
}
*/
return nil
}
var (
indexStatsCmd = app.Command("indexstats",
`collect and display full text index statistics
Each output line contains statistics about a bleve index row type. See:
http://www.blevesearch.com/docs/Index-Structure/
For more details about bleve index structure.
`)
indexPathArg = indexStatsCmd.Arg("path", "index path").String()
)
func indexStatsFn(cfg *Config) error {
return nil
/*
path := *indexPathArg
if path == "" {
path = cfg.Index()
}
index, err := OpenOfferIndex(path)
if err != nil {
return err
}
kinds := map[byte]struct {
Count int
Size int
}{}
unknown := 0
rows := index.DumpAll()
var failed error
for item := range rows {
if failed != nil {
continue
}
switch item.(type) {
case error:
failed = item.(error)
case upsidedown.UpsideDownCouchRow:
row := item.(upsidedown.UpsideDownCouchRow)
key := row.Key()
st := kinds[key[0]]
st.Count++
st.Size += row.KeySize() + row.ValueSize()
kinds[key[0]] = st
default:
unknown++
}
}
totalCount := 0
totalSize := 0
for i := 0; i < 256; i++ {
st, ok := kinds[byte(i)]
if !ok {
continue
}
fmt.Printf("%s: count: %d, size: %.1fkB\n", string([]byte{byte(i)}),
st.Count, float64(st.Size)/1024.)
totalCount += st.Count
totalSize += st.Size
}
fmt.Printf("total: count: %d, size: %.1fkB\n", totalCount, float64(totalSize)/1024.)
if unknown > 0 {
fmt.Printf("unknown rows: %d\n", unknown)
}
return nil
*/
}