-
Notifications
You must be signed in to change notification settings - Fork 61
/
payload.go
49 lines (40 loc) · 1.38 KB
/
payload.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
package tokenattributes
import (
"github.com/balzaczyy/golucene/core/util"
)
/*
The payload of a Token.
The payload is stored in the index at each position, and can be used
to influence scoring when using Payload-based queries in the payloads
and spans packages.
NOTE: becaues the payload will be stored at each position, its
usually best to use the minimum number of bytes necessary. Some codec
implementations may optimize payload storage when all payloads have
the same length.
*/
type PayloadAttribute interface {
util.Attribute
// Returns this Token's payload
Payload() []byte
// Sets this Token's payload.
SetPayload([]byte)
}
/* Default implementation of PayloadAttirbute */
type PayloadAttributeImpl struct {
payload []byte
}
func newPayloadAttributeImpl() util.AttributeImpl {
return new(PayloadAttributeImpl)
}
func (a *PayloadAttributeImpl) Interfaces() []string { return []string{"PayloadAttribute"} }
func (a *PayloadAttributeImpl) Payload() []byte { return a.payload }
func (a *PayloadAttributeImpl) SetPayload(payload []byte) { a.payload = payload }
func (a *PayloadAttributeImpl) Clear() { a.payload = nil }
func (a *PayloadAttributeImpl) Clone() util.AttributeImpl {
return &PayloadAttributeImpl{
payload: a.payload,
}
}
func (a *PayloadAttributeImpl) CopyTo(target util.AttributeImpl) {
target.(PayloadAttribute).SetPayload(a.payload)
}