-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregexp_query.go
131 lines (123 loc) · 4.29 KB
/
regexp_query.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package es
type regexpType Object
// Regexp creates a new es.regexpType object with the specified key-value pair.
//
// This function initializes an es.regexpType object with a single regexp query, where the
// key is the field name and the value is the regexp to search for. This is typically
// used to construct a regexp query in search queries.
//
// Example usage:
//
// t := es.Regexp("endpoint", "/books/.*")
// // t now contains an es.regexpType object with a regexp query for the "endpoint" field.
//
// Parameters:
// - key: A string representing the field name for the regexp query.
// - value: The value to be searched for in the specified field. The type is regexp.
//
// Returns:
//
// An es.regexpType object containing the specified regexp query.
func Regexp(key string, value string) regexpType {
return regexpType{
"regexp": Object{
key: Object{
"value": value,
},
},
}
}
// Flags Enables optional operators for the regular expression.
// Example usage:
//
// regexp := es.Regexp("endpoint", "/books/.*").Flags("ALL")
// // regexp now a "flags" field set "ALL" in the regexp query object.
//
// Parameters:
// - flags: A string value representing flags value to be applied to the regexp query.
//
// Returns:
//
// The updated es.regexpType object with the "flags" field set to the specified value.
func (r regexpType) Flags(flags string) regexpType {
return r.putInTheField("flags", flags)
}
// CaseInsensitive Allows case insensitive matching of the regular expression
// value with the indexed field values when set to true.
// Example usage:
//
// regexp := es.Regexp("endpoint", "/books/.*").CaseInsensitive(true)
// // regexp now a "case_insensitive" field set true in the regexp query object.
//
// Parameters:
// - caseInsensitive: A bool value representing case insensitive value to be applied to the regexp query.
//
// Returns:
//
// The updated es.regexpType object with the "case_insensitive" field set to the specified value.
func (r regexpType) CaseInsensitive(caseInsensitive bool) regexpType {
return r.putInTheField("case_insensitive", caseInsensitive)
}
// MaxDeterminizedStates Maximum number of automaton states required for the query.
// Example usage:
//
// regexp := es.Regexp("endpoint", "/books/.*").MaxDeterminizedStates(10000)
// // regexp now a "max_determinized_states" field set 10000 in the regexp query object.
//
// Parameters:
// - maxDeterminizedStates: A bool value representing max_determinized_states value to be applied to the regexp query.
//
// Returns:
//
// The updated es.regexpType object with the "max_determinized_states" field set to the specified value.
func (r regexpType) MaxDeterminizedStates(maxDeterminizedStates int) regexpType {
return r.putInTheField("max_determinized_states", maxDeterminizedStates)
}
// Rewrite Method used to rewrite the query.
// Example usage:
//
// regexp := es.Regexp("endpoint", "/books/.*").Rewrite("a")
// // regexp now a "rewrite" field set "a" in the regexp query object.
//
// Parameters:
// - rewrite: A string value representing rewrite value to be applied to the regexp query.
//
// Returns:
//
// The updated es.regexpType object with the "rewrite" field set to the specified value.
func (r regexpType) Rewrite(rewrite string) regexpType {
return r.putInTheField("rewrite", rewrite)
}
// Boost sets the "boost" parameter in an es.regexpType query.
//
// This method allows you to specify a boost factor for the regular expression query,
// which influences the relevance score of matching documents. A higher boost value
// increases the importance of the query in the overall score, resulting in higher
// scores for documents that match the regular expression.
//
// Example usage:
//
// r := es.Regexp().Boost(1.2)
// // r now includes a "boost" parameter set to 1.2.
//
// Parameters:
// - boost: A float64 value representing the boost factor for the regular
// expression query.
//
// Returns:
//
// The updated es.regexpType object with the "boost" parameter set.
func (r regexpType) Boost(boost float64) regexpType {
return r.putInTheField("boost", boost)
}
func (r regexpType) putInTheField(key string, value any) regexpType {
if regexp, ok := r["regexp"].(Object); ok {
for _, fieldObj := range regexp {
if fieldObject, foOk := fieldObj.(Object); foOk {
fieldObject[key] = value
break
}
}
}
return r
}