/
case_insensitive.go
50 lines (43 loc) · 1.6 KB
/
case_insensitive.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
package search
import "github.com/tidwall/gjson"
// WithCaseInsensitive is a query mixin that adds the case_insensitive param
//
// (Optional, Boolean) Allows ASCII case insensitive matching of the value with
// the indexed field values when set to true. Default is false which means the
// case sensitivity of matching depends on the underlying field’s mapping.
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
type WithCaseInsensitive interface {
CaseInsensitive() bool
SetCaseInsensitive(v bool)
}
// CaseInsensitiveParam is a query mixin that adds the case_insensitive param
//
// (Optional, Boolean) Allows ASCII case insensitive matching of the value with
// the indexed field values when set to true. Default is false which means the
// case sensitivity of matching depends on the underlying field’s mapping.
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-query.html
type CaseInsensitiveParam struct {
CaseInsensitiveValue *bool `json:"case_insensitive,omitempty" bson:"case_insensitive,omitempty"`
}
func (ci CaseInsensitiveParam) Default() bool {
return false
}
func (ci CaseInsensitiveParam) CaseInsensitive() bool {
if ci.CaseInsensitiveValue == nil {
return ci.Default()
}
return *ci.CaseInsensitiveValue
}
func (ci *CaseInsensitiveParam) SetCaseInsensitive(v bool) {
if ci.CaseInsensitive() != v {
ci.CaseInsensitiveValue = &v
}
}
func unmarshalCaseInsensitiveParam(value gjson.Result, target interface{}) error {
if r, ok := target.(WithCaseInsensitive); ok {
r.SetCaseInsensitive(value.Bool())
}
return nil
}