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

blevesearch / bleve / 21037611517

15 Jan 2026 03:57PM UTC coverage: 52.621% (-1.1%) from 53.696%
21037611517

Pull #2224

github

abhinavdangeti
Upgrade to zapx {v17.0.0, v16.3.0} + re-situate nested test(s)
Pull Request #2224: MB-27666: Hierarchy Search

144 of 979 new or added lines in 29 files covered. (14.71%)

9 existing lines in 5 files now uncovered.

19180 of 36449 relevant lines covered (52.62%)

0.59 hits per line

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

24.79
/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/search"
22
        "github.com/blevesearch/bleve/v2/size"
23
        index "github.com/blevesearch/bleve_index_api"
24
)
25

26
var reflectStaticSizeDocument int
27

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

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

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

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

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

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

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

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

73
        return sizeInBytes
×
74
}
75

76
func (d *Document) AddField(f Field) *Document {
1✔
77
        switch f := f.(type) {
1✔
78
        case *CompositeField:
1✔
79
                d.CompositeFields = append(d.CompositeFields, f)
1✔
80
        default:
1✔
81
                d.Fields = append(d.Fields, f)
1✔
82
        }
83
        return d
1✔
84
}
85

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

104
func (d *Document) NumPlainTextBytes() uint64 {
1✔
105
        rv := uint64(0)
1✔
106
        for _, field := range d.Fields {
2✔
107
                rv += field.NumPlainTextBytes()
1✔
108
        }
1✔
109
        for _, compositeField := range d.CompositeFields {
2✔
110
                for _, field := range d.Fields {
2✔
111
                        if compositeField.includesField(field.Name()) {
2✔
112
                                rv += field.NumPlainTextBytes()
1✔
113
                        }
1✔
114
                }
115
        }
116
        return rv
1✔
117
}
118

119
func (d *Document) ID() string {
×
120
        return d.id
×
121
}
×
122

123
func (d *Document) SetID(id string) {
×
124
        d.id = id
×
125
}
×
126

127
func (d *Document) AddIDField() {
×
128
        d.AddField(NewTextFieldCustom("_id", nil, []byte(d.ID()), index.IndexField|index.StoreField, nil))
×
129
}
×
130

131
func (d *Document) VisitFields(visitor index.FieldVisitor) {
×
132
        for _, f := range d.Fields {
×
133
                visitor(f)
×
134
        }
×
135
}
136

137
func (d *Document) VisitComposite(visitor index.CompositeFieldVisitor) {
×
138
        for _, f := range d.CompositeFields {
×
139
                visitor(f)
×
140
        }
×
141
}
142

143
func (d *Document) HasComposite() bool {
×
144
        return len(d.CompositeFields) > 0
×
145
}
×
146

147
func (d *Document) VisitSynonymFields(visitor index.SynonymFieldVisitor) {
×
148
        for _, f := range d.Fields {
×
149
                if sf, ok := f.(index.SynonymField); ok {
×
150
                        visitor(sf)
×
151
                }
×
152
        }
153
}
154

155
func (d *Document) SetIndexed() {
×
156
        d.indexed = true
×
157
}
×
158

159
func (d *Document) Indexed() bool {
×
160
        return d.indexed
×
161
}
×
162

NEW
163
func (d *Document) AddNestedDocument(doc *Document) {
×
NEW
164
        d.NestedDocuments = append(d.NestedDocuments, doc)
×
NEW
165
}
×
166

NEW
167
func (d *Document) NestedFields() search.FieldSet {
×
NEW
168
        if len(d.NestedDocuments) == 0 {
×
NEW
169
                return nil
×
NEW
170
        }
×
NEW
171
        fieldSet := search.NewFieldSet()
×
NEW
172
        var collectFields func(index.Document)
×
NEW
173
        collectFields = func(doc index.Document) {
×
NEW
174
                // Add all field names from this nested document
×
NEW
175
                doc.VisitFields(func(field index.Field) {
×
NEW
176
                        fieldSet.AddField(field.Name())
×
NEW
177
                })
×
178
                // Recursively collect from this document's nested documents
NEW
179
                if nd, ok := doc.(index.NestedDocument); ok {
×
NEW
180
                        nd.VisitNestedDocuments(collectFields)
×
NEW
181
                }
×
182
        }
183
        // Start collection from nested documents only (not root document)
NEW
184
        d.VisitNestedDocuments(collectFields)
×
NEW
185
        return fieldSet
×
186
}
187

NEW
188
func (d *Document) VisitNestedDocuments(visitor func(doc index.Document)) {
×
NEW
189
        for _, doc := range d.NestedDocuments {
×
NEW
190
                visitor(doc)
×
NEW
191
        }
×
192
}
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