-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsph.go
98 lines (86 loc) · 2.42 KB
/
sph.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
package main
import (
"fmt"
"io"
"os"
)
const IndexMagicHeader uint32 = 0x58485053
const SPHVersion uint32 = 63
type sph struct {
metahdr
Schema indexschema
// dictionary header (wordlist checkpoints, infix blocks, etc)
DictCheckpointsOffset uint64
DictCheckPoints uint32
InfixCodepointBytes byte
InfixBlockOffset,
InfixBlockWordSize uint32
// index stats
TotalDocuments uint32
TotalBytes uint64
IndexSettings indexsettings
TokenizerSettings tokenizerSettings
DictSettings dictSettings
Docinfo, DocinfoIndex, MinMaxIndex uint64
FieldLens []uint64
FieldFilterSettings fieldFilterSettings
}
func (h *sph) load(r io.Reader) {
h.Magic = getDword(r)
h.Version = getDword(r)
h.Schema.load(r, h.Version)
h.DictCheckpointsOffset, h.DictCheckPoints = getUint64(r), getDword(r)
h.InfixCodepointBytes = getByte(r)
h.InfixBlockOffset, h.InfixBlockWordSize = getDword(r), getDword(r)
h.TotalDocuments = getDword(r)
h.TotalBytes = getUint64(r)
h.IndexSettings.load(r, h.Version)
h.TokenizerSettings.load(r)
h.DictSettings.load(r)
h.Docinfo = getUint64(r)
h.DocinfoIndex = getUint64(r)
h.MinMaxIndex = getUint64(r)
h.FieldFilterSettings.load(r)
if h.IndexSettings.IndexFieldLens {
lng := len(h.Schema.Fields)
h.FieldLens = make([]uint64, lng)
for i := 0; i < lng; i++ {
h.FieldLens[i] = getUint64(r)
}
}
}
func (h *sph) save(w io.Writer) {
saveDword(w, h.Magic)
saveDword(w, h.Version)
h.Schema.save(w, h.Version)
saveUint64(w, h.DictCheckpointsOffset)
saveDword(w, h.DictCheckPoints)
saveByte(w, h.InfixCodepointBytes)
saveDword(w, h.InfixBlockOffset)
saveDword(w, h.InfixBlockWordSize)
saveDword(w, h.TotalDocuments)
saveUint64(w, h.TotalBytes)
h.IndexSettings.save(w, h.Version)
h.TokenizerSettings.save(w)
h.DictSettings.save(w)
saveUint64(w, h.Docinfo)
saveUint64(w, h.DocinfoIndex)
saveUint64(w, h.MinMaxIndex)
h.FieldFilterSettings.save(w)
if h.IndexSettings.IndexFieldLens {
lng := len(h.Schema.Fields)
h.FieldLens = make([]uint64, lng)
for i := 0; i < lng; i++ {
saveUint64(w, h.FieldLens[i])
}
}
}
func (h *metahdr) isSph() bool {
return h.Magic == IndexMagicHeader
}
func (h *sph) Checkvalid() {
if h.Magic != IndexMagicHeader {
fmt.Printf("Wrong magic of the index: expected %d, got %d\n", IndexMagicHeader, h.Magic)
os.Exit(1)
}
}