github.com/balzaczyy/golucene@v0.0.0-20151210033525-d0be9ee89713/core/analysis/tokenattributes/payload.go (about) 1 package tokenattributes 2 3 import ( 4 "github.com/balzaczyy/golucene/core/util" 5 ) 6 7 /* 8 The payload of a Token. 9 10 The payload is stored in the index at each position, and can be used 11 to influence scoring when using Payload-based queries in the payloads 12 and spans packages. 13 14 NOTE: becaues the payload will be stored at each position, its 15 usually best to use the minimum number of bytes necessary. Some codec 16 implementations may optimize payload storage when all payloads have 17 the same length. 18 */ 19 type PayloadAttribute interface { 20 util.Attribute 21 // Returns this Token's payload 22 Payload() []byte 23 // Sets this Token's payload. 24 SetPayload([]byte) 25 } 26 27 /* Default implementation of PayloadAttirbute */ 28 type PayloadAttributeImpl struct { 29 payload []byte 30 } 31 32 func newPayloadAttributeImpl() util.AttributeImpl { 33 return new(PayloadAttributeImpl) 34 } 35 36 func (a *PayloadAttributeImpl) Interfaces() []string { return []string{"PayloadAttribute"} } 37 func (a *PayloadAttributeImpl) Payload() []byte { return a.payload } 38 func (a *PayloadAttributeImpl) SetPayload(payload []byte) { a.payload = payload } 39 func (a *PayloadAttributeImpl) Clear() { a.payload = nil } 40 41 func (a *PayloadAttributeImpl) Clone() util.AttributeImpl { 42 return &PayloadAttributeImpl{ 43 payload: a.payload, 44 } 45 } 46 47 func (a *PayloadAttributeImpl) CopyTo(target util.AttributeImpl) { 48 target.(PayloadAttribute).SetPayload(a.payload) 49 }