-
Notifications
You must be signed in to change notification settings - Fork 0
/
srv_search_match.go
105 lines (81 loc) · 2.01 KB
/
srv_search_match.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package elasticsearch
import "encoding/json"
type operator string
type zeroTermsQuery string
const (
OperatorAnd operator = "and"
OperatorOr operator = "or"
ZeroTermsQueryAll zeroTermsQuery = "all"
ZeroTermsQueryNone zeroTermsQuery = "none"
)
type Match struct {
mappings map[string]interface{}
field string
}
func NewMatch(field string, query string) *Match {
new := &Match{
mappings: make(map[string]interface{}),
field: field,
}
new.mappings["query"] = query
return new
}
func (m *Match) Operator(value operator) *Match {
m.mappings["operator"] = value
return m
}
func (m *Match) MinimumShouldMatch(value string) *Match {
m.mappings["minimum_should_match"] = value
return m
}
func (m *Match) Analyzer(value string) *Match {
m.mappings["analyzer"] = value
return m
}
func (m *Match) Lenient(value bool) *Match {
m.mappings["lenient"] = value
return m
}
func (m *Match) Fuzziness(value string) *Match {
m.mappings["fuzziness"] = value
return m
}
func (m *Match) FuzzyRewrite(value string) *Match {
m.mappings["fuzzy_rewrite"] = value
return m
}
func (m *Match) FuzzyTranspositions(value bool) *Match {
m.mappings["fuzzy_transpositions"] = value
return m
}
func (m *Match) PrefixLength(value int64) *Match {
m.mappings["prefix_length"] = value
return m
}
func (m *Match) MaxExpansions(value int64) *Match {
m.mappings["max_expansions"] = value
return m
}
func (m *Match) ZeroTermsQuery(value zeroTermsQuery) *Match {
m.mappings["zero_terms_query"] = value
return m
}
func (m *Match) CutoffFrequency(value float64) *Match {
m.mappings["cutoff_frequency"] = value
return m
}
func (m *Match) AutoGenerateSynonymsPhraseQuery(value bool) *Match {
m.mappings["auto_generate_synonyms_phrase_query"] = value
return m
}
func (m *Match) Data() interface{} {
data := map[string]map[string]interface{}{"match": {m.field: m.mappings}}
return data
}
func (m *Match) Bytes() []byte {
bytes, _ := json.Marshal(m.Data())
return bytes
}
func (m *Match) String() string {
return string(m.Bytes())
}