-
Notifications
You must be signed in to change notification settings - Fork 0
/
metapq.go
79 lines (69 loc) · 1.61 KB
/
metapq.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
package main
import (
"fmt"
"io"
"os"
)
const MetaHeaderMagicPq uint32 = 0x50535451 ///< my magic 'PSTQ' header
const MetaVersionPq uint32 = 8
type metapq struct {
metahdr
IndexVersion uint32
Schema indexschema
IndexSettings indexsettings
TokSettings tokenizerSettings
DictSettings dictSettings
FieldFilterSettings fieldFilterSettings
Queries []storedQueryDesc
Tid int64
}
func (m *metapq) load(r io.Reader) {
// m.Hdr.load(r)
m.IndexVersion = getDword(r)
m.Schema.load(r, m.IndexVersion)
m.IndexSettings.load(r, m.IndexVersion)
m.TokSettings.load(r)
m.DictSettings.load(r)
if m.Version >= 6 {
m.FieldFilterSettings.load(r)
}
nQueries := getDword(r)
m.Queries = make([]storedQueryDesc, nQueries)
for i := 0; i < int(nQueries); i++ {
m.Queries[i].load(r, m.Version)
}
if m.Version > 6 {
m.Tid = getInt64(r)
}
}
func (m *metapq) save(w io.Writer) {
m.metahdr.save(w)
saveDword(w, m.IndexVersion)
m.Schema.save(w, m.IndexVersion)
m.IndexSettings.save(w, m.IndexVersion)
m.TokSettings.save(w)
m.DictSettings.save(w)
if m.Version >= 6 {
m.FieldFilterSettings.save(w)
}
nQueries := len(m.Queries)
saveDword(w, uint32(nQueries))
if nQueries == 0 {
return
}
for i := 0; i < nQueries; i++ {
m.Queries[i].save(w, m.Version)
}
if m.Version > 6 {
saveUint64(w, i2u64(m.Tid))
}
}
func (h *metahdr) isPq() bool {
return h.Magic == MetaHeaderMagicPq
}
func (m *metapq) Checkvalid() {
if m.Magic != MetaHeaderMagicPq {
fmt.Printf("Wrong magic of the index: expected %d, got %d\n", MetaHeaderMagicPq, m.Magic)
os.Exit(1)
}
}