/
analyzer.go
47 lines (41 loc) · 1.54 KB
/
analyzer.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
package search
import "github.com/tidwall/gjson"
// WithAnalyzer is a query with the analyzer param
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html
type WithAnalyzer interface {
// Analyzer used to convert the text in the query value into tokens.
// Defaults to the index-time analyzer mapped for the <field>. If no
// analyzer is mapped, the index’s default analyzer is used. (Optional)
Analyzer() string
// SetAnalyzer sets the Analyzer value to v
SetAnalyzer(v string)
}
func unmarshalAnalyzerParam(value gjson.Result, target interface{}) error {
if a, ok := target.(WithAnalyzer); ok {
a.SetAnalyzer(value.Str)
}
return nil
}
// AnalyzerParam is a query mixin that adds the analyzer param
//
// Analyzer used to convert the text in the query value into tokens.
// Defaults to the index-time analyzer mapped for the <field>. If no
// analyzer is mapped, the index’s default analyzer is used. (Optional)
//
// https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html
type AnalyzerParam struct {
AnalyzerValue string `json:"analyzer,omitempty" bson:"analyzer,omitempty"`
}
// Analyzer used to convert the text in the query value into tokens.
// Defaults to the index-time analyzer mapped for the <field>. If no
// analyzer is mapped, the index’s default analyzer is used. (Optional)
func (a AnalyzerParam) Analyzer() string {
return a.AnalyzerValue
}
// SetAnalyzer sets the Analyzer value to v
func (a *AnalyzerParam) SetAnalyzer(v string) {
if a.Analyzer() != v {
a.AnalyzerValue = v
}
}