summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/blevesearch/bleve/document/document.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/blevesearch/bleve/document/document.go')
-rw-r--r--vendor/github.com/blevesearch/bleve/document/document.go29
1 files changed, 28 insertions, 1 deletions
diff --git a/vendor/github.com/blevesearch/bleve/document/document.go b/vendor/github.com/blevesearch/bleve/document/document.go
index c37585c661..6ac17b9ab7 100644
--- a/vendor/github.com/blevesearch/bleve/document/document.go
+++ b/vendor/github.com/blevesearch/bleve/document/document.go
@@ -14,7 +14,19 @@
package document
-import "fmt"
+import (
+ "fmt"
+ "reflect"
+
+ "github.com/blevesearch/bleve/size"
+)
+
+var reflectStaticSizeDocument int
+
+func init() {
+ var d Document
+ reflectStaticSizeDocument = int(reflect.TypeOf(d).Size())
+}
type Document struct {
ID string `json:"id"`
@@ -30,6 +42,21 @@ func NewDocument(id string) *Document {
}
}
+func (d *Document) Size() int {
+ sizeInBytes := reflectStaticSizeDocument + size.SizeOfPtr +
+ len(d.ID)
+
+ for _, entry := range d.Fields {
+ sizeInBytes += entry.Size()
+ }
+
+ for _, entry := range d.CompositeFields {
+ sizeInBytes += entry.Size()
+ }
+
+ return sizeInBytes
+}
+
func (d *Document) AddField(f Field) *Document {
switch f := f.(type) {
case *CompositeField: