/
maxInputLength.go
53 lines (46 loc) · 2.07 KB
/
maxInputLength.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
50
51
52
53
package mapping
// WithMaxInputLength is a mapping with the max_input_length parameter
//
// Limits the length of a single input, defaults to 50 UTF-16 code points. This
// limit is only used at index time to reduce the total number of characters per
// input string in order to prevent massive inputs from bloating the underlying
// datastructure. Most use cases won’t be influenced by the default value since
// prefix completions seldom grow beyond prefixes longer than a handful of
// characters.
type WithMaxInputLength interface {
// MaxInputLength limits the length of a single input, defaults to 50 UTF-16
// code points. This limit is only used at index time to reduce the total
// number of characters per input string in order to prevent massive inputs
// from bloating the underlying datastructure. Most use cases won’t be
// influenced by the default value since prefix completions seldom grow
// beyond prefixes longer than a handful of characters.
MaxInputLength() int
// SetMaxInputLength sets the MaxInputLength value to v
SetMaxInputLength(v int)
}
// FieldWithMaxInputLength is a Field mapping with the max_input_length parameter
type FieldWithMaxInputLength interface {
Field
WithMaxInputLength
}
type MaxInputLengthParam struct {
MaxInputLengthValue *int `bson:"max_input_length,omitempty" json:"max_input_length,omitempty"`
}
// MaxInputLength limits the length of a single input, defaults to 50 UTF-16
// code points. This limit is only used at index time to reduce the total
// number of characters per input string in order to prevent massive inputs
// from bloating the underlying datastructure. Most use cases won’t be
// influenced by the default value since prefix completions seldom grow
// beyond prefixes longer than a handful of characters.
func (mil MaxInputLengthParam) MaxInputLength() int {
if mil.MaxInputLengthValue == nil {
return 50
}
return *mil.MaxInputLengthValue
}
// SetMaxInputLength sets the MaxInputLength value to v
func (mil *MaxInputLengthParam) SetMaxInputLength(v int) {
if mil.MaxInputLength() != v {
mil.MaxInputLengthValue = &v
}
}