/
max_shingle_size.go
61 lines (56 loc) · 2.19 KB
/
max_shingle_size.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
54
55
56
57
58
59
60
61
package mapping
// WithMaxShingleSize is a mapping with the max_shingle_size parameter
//
// (Optional, integer) Largest shingle size to create. Valid values are 2
// (inclusive) to 4 (inclusive). Defaults to 3.
//
// A subfield is created for each integer between 2 and this value. For example,
// a value of 3 creates two subfields: my_field._2gram and my_field._3gram
//
// More subfields enables more specific queries but increases index size.
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-as-you-type.html#specific-params
type WithMaxShingleSize interface {
// MaxShingleSize is the largest shingle size to create. Valid values are 2
// (inclusive) to 4 (inclusive). Defaults to 3.
MaxShingleSize() int
// SetMaxShingleSize sets the MaxShingleSize to v
//
// Valid values are 2 (inclusive) to 4 (inclusive). Defaults to 3.
SetMaxShingleSize(v int)
}
// FieldWithMaxShingleSize is a Field mapping with the max_shingle_size parameter
type FieldWithMaxShingleSize interface {
Field
WithMaxShingleSize
}
// MaxShingleSizeParam is a mixin that adds the max_shingle_size parameter
//
// (Optional, integer) Largest shingle size to create. Valid values are 2
// (inclusive) to 4 (inclusive). Defaults to 3.
//
// A subfield is created for each integer between 2 and this value. For example,
// a value of 3 creates two subfields: my_field._2gram and my_field._3gram
//
// More subfields enables more specific queries but increases index size.
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-as-you-type.html#specific-params
type MaxShingleSizeParam struct {
MaxShingleSizeValue *int `bson:"max_shingle_size,omitempty" json:"max_shingle_size,omitempty"`
}
// MaxShingleSize is the largest shingle size to create. Valid values are 2
// (inclusive) to 4 (inclusive). Defaults to 3.
func (mss MaxShingleSizeParam) MaxShingleSize() int {
if mss.MaxShingleSizeValue == nil {
return 3
}
return *mss.MaxShingleSizeValue
}
// SetMaxShingleSize sets the MaxShingleSize to v
//
// Valid values are 2 (inclusive) to 4 (inclusive). Defaults to 3.
func (mss *MaxShingleSizeParam) SetMaxShingleSize(v int) {
if mss.MaxShingleSize() != v {
mss.MaxShingleSizeValue = &v
}
}