-
Notifications
You must be signed in to change notification settings - Fork 12
/
doc_test.go
178 lines (147 loc) · 3.59 KB
/
doc_test.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package zap
import (
"strings"
index "github.com/blevesearch/bleve_index_api"
)
type stubDocument struct {
id string
fields []*stubField
composite []*stubField
}
func (s *stubDocument) StoredFieldsBytes() uint64 {
return 0
}
func (s *stubDocument) ID() string {
return s.id
}
func (s *stubDocument) Size() int {
return 0
}
func (s *stubDocument) VisitFields(visitor index.FieldVisitor) {
for _, f := range s.fields {
visitor(f)
}
}
func (s *stubDocument) HasComposite() bool {
return len(s.composite) > 0
}
func (s *stubDocument) VisitComposite(visitor index.CompositeFieldVisitor) {
for _, c := range s.composite {
visitor(c)
}
}
func (s *stubDocument) NumPlainTextBytes() uint64 {
return 0
}
func (s *stubDocument) AddIDField() {
}
func newStubDocument(id string, fields []*stubField, compositeName string) *stubDocument {
rv := &stubDocument{
id: id,
fields: fields,
}
// fixup composite
cf := &stubField{
name: compositeName,
value: nil,
arrayPositions: nil,
encodedType: 'c',
options: index.IndexField | index.IncludeTermVectors,
analyzedLen: 0,
analyzedFreqs: make(index.TokenFrequencies),
}
for _, f := range rv.fields {
if f.name == "_id" {
continue
}
cf.analyzedLen += f.analyzedLen
cf.analyzedFreqs.MergeAll(f.name, f.analyzedFreqs)
}
rv.composite = []*stubField{cf}
return rv
}
type stubField struct {
name string
value []byte
arrayPositions []uint64
encodedType byte
options index.FieldIndexingOptions
analyzedLen int
analyzedFreqs index.TokenFrequencies
}
func newStubFieldSplitString(name string, arrayPositions []uint64, value string, stored, docVals, termVectors bool) *stubField {
tokens := strings.Split(value, " ")
analyzedFreqs := make(index.TokenFrequencies)
var offset int
for i, token := range tokens {
curr, exists := analyzedFreqs[token]
if exists {
curr.SetFrequency(curr.Frequency() + 1)
if termVectors {
curr.Locations = append(curr.Locations, &index.TokenLocation{
ArrayPositions: arrayPositions,
Start: offset,
End: offset + len(token),
Position: i + 1,
})
}
} else {
newToken := &index.TokenFreq{
Term: []byte(token),
Locations: []*index.TokenLocation{{
ArrayPositions: arrayPositions,
Start: offset,
End: offset + len(token),
Position: i + 1,
}},
}
newToken.SetFrequency(1)
analyzedFreqs[token] = newToken
}
offset += len(token) + 1
}
var fieldOptions = index.IndexField | index.IncludeTermVectors
if stored {
fieldOptions |= index.StoreField
}
if docVals {
fieldOptions |= index.DocValues
}
return &stubField{
name: name,
value: []byte(value),
arrayPositions: arrayPositions,
encodedType: 't',
options: fieldOptions,
analyzedLen: len(analyzedFreqs),
analyzedFreqs: analyzedFreqs,
}
}
func (s *stubField) Name() string {
return s.name
}
func (s *stubField) Value() []byte {
return s.value
}
func (s *stubField) ArrayPositions() []uint64 {
return s.arrayPositions
}
func (s *stubField) EncodedFieldType() byte {
return s.encodedType
}
func (s *stubField) Analyze() {
}
func (s *stubField) Options() index.FieldIndexingOptions {
return s.options
}
func (s *stubField) AnalyzedLength() int {
return s.analyzedLen
}
func (s *stubField) AnalyzedTokenFrequencies() index.TokenFrequencies {
return s.analyzedFreqs
}
func (s *stubField) NumPlainTextBytes() uint64 {
return 0
}
func (s *stubField) Compose(field string, length int, freq index.TokenFrequencies) {
}