• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blevesearch / bleve / 25041449220

28 Apr 2026 08:07AM UTC coverage: 51.835% (-0.009%) from 51.844%
25041449220

push

github

web-flow
Fix metrics involving NestedDocuments (#2325)

- Fix `Size` calculation to include size of `NestedDocuments` as well.

Co-authored-by: Copilot <copilot@github.com>

1 of 8 new or added lines in 1 file covered. (12.5%)

3 existing lines in 2 files now uncovered.

19560 of 37735 relevant lines covered (51.84%)

0.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

27.52
/document/document.go
1
//  Copyright (c) 2014 Couchbase, Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//                 http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package document
16

17
import (
18
        "fmt"
19
        "reflect"
20

21
        "github.com/blevesearch/bleve/v2/size"
22
        index "github.com/blevesearch/bleve_index_api"
23
)
24

25
var reflectStaticSizeDocument int
26

27
func init() {
1✔
28
        var d Document
1✔
29
        reflectStaticSizeDocument = int(reflect.TypeOf(d).Size())
1✔
30
}
1✔
31

32
type Document struct {
33
        id               string
34
        Fields           []Field     `json:"fields"`
35
        NestedDocuments  []*Document `json:"nested_documents"`
36
        CompositeFields  []*CompositeField
37
        StoredFieldsSize uint64
38
        indexed          bool
39
}
40

41
func (d *Document) StoredFieldsBytes() uint64 {
×
42
        return d.StoredFieldsSize
×
43
}
×
44

45
func NewDocument(id string) *Document {
1✔
46
        return &Document{
1✔
47
                id:              id,
1✔
48
                Fields:          make([]Field, 0),
1✔
49
                CompositeFields: make([]*CompositeField, 0),
1✔
50
        }
1✔
51
}
1✔
52

53
func NewSynonymDocument(id string) *Document {
×
54
        return &Document{
×
55
                id:     id,
×
56
                Fields: make([]Field, 0),
×
57
        }
×
58
}
×
59

60
func (d *Document) Size() int {
×
61
        sizeInBytes := reflectStaticSizeDocument + size.SizeOfPtr +
×
62
                len(d.id)
×
63

×
64
        for _, entry := range d.Fields {
×
65
                sizeInBytes += entry.Size()
×
66
        }
×
67

68
        for _, entry := range d.CompositeFields {
×
69
                sizeInBytes += entry.Size()
×
70
        }
×
71

NEW
72
        for _, entry := range d.NestedDocuments {
×
NEW
73
                if entry != nil {
×
NEW
74
                        sizeInBytes += entry.Size()
×
NEW
75
                }
×
76
        }
77

UNCOV
78
        return sizeInBytes
×
79
}
80

81
func (d *Document) AddField(f Field) *Document {
1✔
82
        switch f := f.(type) {
1✔
83
        case *CompositeField:
1✔
84
                d.CompositeFields = append(d.CompositeFields, f)
1✔
85
        default:
1✔
86
                d.Fields = append(d.Fields, f)
1✔
87
        }
88
        return d
1✔
89
}
90

91
func (d *Document) GoString() string {
×
92
        fields := ""
×
93
        for i, field := range d.Fields {
×
94
                if i != 0 {
×
95
                        fields += ", "
×
96
                }
×
97
                fields += fmt.Sprintf("%#v", field)
×
98
        }
99
        compositeFields := ""
×
100
        for i, field := range d.CompositeFields {
×
101
                if i != 0 {
×
102
                        compositeFields += ", "
×
103
                }
×
104
                compositeFields += fmt.Sprintf("%#v", field)
×
105
        }
106
        return fmt.Sprintf("&document.Document{ID:%s, Fields: %s, CompositeFields: %s}", d.ID(), fields, compositeFields)
×
107
}
108

109
func (d *Document) NumPlainTextBytes() uint64 {
1✔
110
        rv := uint64(0)
1✔
111
        for _, field := range d.Fields {
2✔
112
                rv += field.NumPlainTextBytes()
1✔
113
        }
1✔
114
        for _, compositeField := range d.CompositeFields {
2✔
115
                for _, field := range d.Fields {
2✔
116
                        if compositeField.includesField(field.Name()) {
2✔
117
                                rv += field.NumPlainTextBytes()
1✔
118
                        }
1✔
119
                }
120
        }
121
        for _, nestedDoc := range d.NestedDocuments {
1✔
NEW
122
                if nestedDoc != nil {
×
NEW
123
                        rv += nestedDoc.NumPlainTextBytes()
×
NEW
124
                }
×
125
        }
126
        return rv
1✔
127
}
128

129
func (d *Document) ID() string {
×
130
        return d.id
×
131
}
×
132

133
func (d *Document) SetID(id string) {
×
134
        d.id = id
×
135
}
×
136

137
func (d *Document) AddIDField() {
×
138
        d.AddField(NewTextFieldCustom("_id", nil, []byte(d.ID()), index.IndexField|index.StoreField, nil))
×
139
}
×
140

141
func (d *Document) VisitFields(visitor index.FieldVisitor) {
×
142
        for _, f := range d.Fields {
×
143
                visitor(f)
×
144
        }
×
145
}
146

147
func (d *Document) VisitComposite(visitor index.CompositeFieldVisitor) {
×
148
        for _, f := range d.CompositeFields {
×
149
                visitor(f)
×
150
        }
×
151
}
152

153
func (d *Document) HasComposite() bool {
×
154
        return len(d.CompositeFields) > 0
×
155
}
×
156

157
func (d *Document) VisitSynonymFields(visitor index.SynonymFieldVisitor) {
×
158
        for _, f := range d.Fields {
×
159
                if sf, ok := f.(index.SynonymField); ok {
×
160
                        visitor(sf)
×
161
                }
×
162
        }
163
}
164

165
func (d *Document) SetIndexed() {
×
166
        d.indexed = true
×
167
}
×
168

169
func (d *Document) Indexed() bool {
×
170
        return d.indexed
×
171
}
×
172

173
func (d *Document) AddNestedDocument(doc *Document) {
×
174
        d.NestedDocuments = append(d.NestedDocuments, doc)
×
175
}
×
176

177
func (d *Document) VisitNestedDocuments(visitor func(doc index.Document)) {
×
178
        for _, doc := range d.NestedDocuments {
×
179
                visitor(doc)
×
180
        }
×
181
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc