1
1
package es
2
2
3
- import Operator "github.com/Trendyol/es-query-builder/es/enums/match/operator"
3
+ import (
4
+ Operator "github.com/Trendyol/es-query-builder/es/enums/match/operator"
5
+ ZeroTermsQuery "github.com/Trendyol/es-query-builder/es/enums/match/zero-terms-query"
6
+ )
4
7
5
8
type matchType Object
6
9
@@ -12,7 +15,7 @@ type matchType Object
12
15
//
13
16
// Example usage:
14
17
//
15
- // m := Match("title", "es-query-builder")
18
+ // m := es. Match("title", "es-query-builder")
16
19
// // m now contains a matchType object that matches the query "es-query-builder" in the "title" field.
17
20
//
18
21
// Parameters:
@@ -47,12 +50,11 @@ func (m matchType) putInTheField(key string, value any) matchType {
47
50
// Operator sets the "operator" field in the match query.
48
51
//
49
52
// This method configures the match query to use a specified operator (e.g., "AND" or "OR")
50
- // for the matching process. It calls putInTheField to add or update the "operator" key
51
- // in the match query object.
53
+ // for the matching process.
52
54
//
53
55
// Example usage:
54
56
//
55
- // m := Match("title", "es-query-builder").Operator("AND")
57
+ // m := es. Match("title", "es-query-builder").Operator("AND")
56
58
// // m now has an "operator" field set to "AND" in the match query object.
57
59
//
58
60
// Parameters:
@@ -68,12 +70,11 @@ func (m matchType) Operator(operator Operator.Operator) matchType {
68
70
// Boost sets the "boost" field in the match query.
69
71
//
70
72
// This method configures the match query to use a specified boost factor, which influences
71
- // the relevance scoring of the matched documents. It calls putInTheField to add or update
72
- // the "boost" key in the match query object.
73
+ // the relevance scoring of the matched documents.
73
74
//
74
75
// Example usage:
75
76
//
76
- // m := Match("title", "es-query-builder").Boost(1.5)
77
+ // m := es. Match("title", "es-query-builder").Boost(1.5)
77
78
// // m now has a "boost" field set to 1.5 in the match query object.
78
79
//
79
80
// Parameters:
@@ -85,3 +86,174 @@ func (m matchType) Operator(operator Operator.Operator) matchType {
85
86
func (m matchType ) Boost (boost float64 ) matchType {
86
87
return m .putInTheField ("boost" , boost )
87
88
}
89
+
90
+ // CutoffFrequency sets the "cutoff_frequency" field in the match query.
91
+ //
92
+ // This method configures the match query to use a specified cutoff frequency, which is useful
93
+ // for controlling how often terms should appear in the document for it to be considered a match.
94
+ // A lower cutoff frequency increases precision, while a higher one allows more terms to be matched.
95
+ //
96
+ // Example usage:
97
+ //
98
+ // m := es.Match("title", "es-query-builder").CutoffFrequency(0.001)
99
+ // // m now has a "cutoff_frequency" field set to 0.001 in the match query object.
100
+ //
101
+ // Parameters:
102
+ // - cutoffFrequency: A float64 value representing the cutoff frequency threshold to be used in the match query.
103
+ //
104
+ // Returns:
105
+ //
106
+ // The updated matchType object with the "cutoff_frequency" field set to the specified value.
107
+ func (m matchType ) CutoffFrequency (cutoffFrequency float64 ) matchType {
108
+ return m .putInTheField ("cutoff_frequency" , cutoffFrequency )
109
+ }
110
+
111
+ // Fuzziness sets the "fuzziness" field in the match query.
112
+ //
113
+ // This method configures the match query to use a specified fuzziness level, which determines
114
+ // the allowed edit distance (e.g., number of character changes) for a term to be considered a match.
115
+ // Common values include "AUTO", or integers representing the number of edits (e.g., 1 or 2).
116
+ //
117
+ // Example usage:
118
+ //
119
+ // m := es.Match("title", "es-query-builder").Fuzziness("AUTO")
120
+ // // m now has a "fuzziness" field set to "AUTO" in the match query object.
121
+ //
122
+ // Parameters:
123
+ // - fuzziness: A value of any type (typically a string or integer) representing the fuzziness level to be applied to the match query.
124
+ //
125
+ // Returns:
126
+ //
127
+ // The updated matchType object with the "fuzziness" field set to the specified value.
128
+ func (m matchType ) Fuzziness (fuzziness any ) matchType {
129
+ return m .putInTheField ("fuzziness" , fuzziness )
130
+ }
131
+
132
+ // FuzzyRewrite sets the "fuzzy_rewrite" field in the match query.
133
+ //
134
+ // This method configures the match query to use a specified fuzzy rewrite method,
135
+ // which controls how multi-term queries are rewritten. Common values include "constant_score",
136
+ // "scoring_boolean", and other rewrite options that influence the scoring and performance of
137
+ // fuzzy matching.
138
+ //
139
+ // Example usage:
140
+ //
141
+ // m := es.Match("title", "es-query-builder").FuzzyRewrite("constant_score")
142
+ // // m now has a "fuzzy_rewrite" field set to "constant_score" in the match query object.
143
+ //
144
+ // Parameters:
145
+ // - fuzzyRewrite: A string value representing the rewrite method to be used for fuzzy matching in the match query.
146
+ //
147
+ // Returns:
148
+ //
149
+ // The updated matchType object with the "fuzzy_rewrite" field set to the specified value.
150
+ func (m matchType ) FuzzyRewrite (fuzzyRewrite string ) matchType {
151
+ return m .putInTheField ("fuzzy_rewrite" , fuzzyRewrite )
152
+ }
153
+
154
+ // FuzzyTranspositions sets the "fuzzy_transpositions" field in the match query.
155
+ //
156
+ // This method configures the match query to allow or disallow transpositions (e.g., swapping two adjacent characters)
157
+ // when performing fuzzy matching. Setting this field to true enables transpositions, which can increase the match rate
158
+ // for terms with common typos or character swaps.
159
+ //
160
+ // Example usage:
161
+ //
162
+ // m := es.Match("title", "es-query-builder").FuzzyTranspositions(true)
163
+ // // m now has a "fuzzy_transpositions" field set to true in the match query object.
164
+ //
165
+ // Parameters:
166
+ // - fuzzyTranspositions: A boolean value indicating whether transpositions should be allowed in fuzzy matching.
167
+ //
168
+ // Returns:
169
+ //
170
+ // The updated matchType object with the "fuzzy_transpositions" field set to the specified value.
171
+ func (m matchType ) FuzzyTranspositions (fuzzyTranspositions bool ) matchType {
172
+ return m .putInTheField ("fuzzy_transpositions" , fuzzyTranspositions )
173
+ }
174
+
175
+ // Lenient sets the "lenient" field in the match query.
176
+ //
177
+ // This method configures the match query to use lenient parsing, allowing it to skip errors
178
+ // for data type mismatches. When set to true, documents that contain mismatched data types
179
+ // (e.g., text in a numeric field) will not cause errors and will be ignored instead.
180
+ //
181
+ // Example usage:
182
+ //
183
+ // m := es.Match("title", "es-query-builder").Lenient(true)
184
+ // // m now has a "lenient" field set to true in the match query object.
185
+ //
186
+ // Parameters:
187
+ // - lenient: A boolean value indicating whether lenient parsing should be enabled.
188
+ //
189
+ // Returns:
190
+ //
191
+ // The updated matchType object with the "lenient" field set to the specified value.
192
+ func (m matchType ) Lenient (lenient bool ) matchType {
193
+ return m .putInTheField ("lenient" , lenient )
194
+ }
195
+
196
+ // MaxExpansions sets the "max_expansions" field in the match query.
197
+ //
198
+ // This method configures the match query to limit the maximum number of terms that can be expanded
199
+ // for multi-term queries, such as those involving fuzzy matching. Higher values allow more terms to
200
+ // be considered, but may impact performance.
201
+ //
202
+ // Example usage:
203
+ //
204
+ // m := es.Match("title", "es-query-builder").MaxExpansions(50)
205
+ // // m now has a "max_expansions" field set to 50 in the match query object.
206
+ //
207
+ // Parameters:
208
+ // - maxExpansions: An integer representing the maximum number of term expansions to be allowed in the match query.
209
+ //
210
+ // Returns:
211
+ //
212
+ // The updated matchType object with the "max_expansions" field set to the specified value.
213
+ func (m matchType ) MaxExpansions (maxExpansions int ) matchType {
214
+ return m .putInTheField ("max_expansions" , maxExpansions )
215
+ }
216
+
217
+ // PrefixLength sets the "prefix_length" field in the match query.
218
+ //
219
+ // This method configures the match query to specify a minimum prefix length for fuzzy matching,
220
+ // which defines the number of initial characters in a term that must match exactly before
221
+ // considering fuzziness. Increasing this value can improve performance by reducing the number
222
+ // of fuzzy matches, but may also limit the flexibility of the query.
223
+ //
224
+ // Example usage:
225
+ //
226
+ // m := es.Match("title", "es-query-builder").PrefixLength(2)
227
+ // // m now has a "prefix_length" field set to 2 in the match query object.
228
+ //
229
+ // Parameters:
230
+ // - prefixLength: An integer representing the number of initial characters that must match exactly in fuzzy matching.
231
+ //
232
+ // Returns:
233
+ //
234
+ // The updated matchType object with the "prefix_length" field set to the specified value.
235
+ func (m matchType ) PrefixLength (prefixLength int ) matchType {
236
+ return m .putInTheField ("prefix_length" , prefixLength )
237
+ }
238
+
239
+ // ZeroTermsQuery sets the "zero_terms_query" field in the match query.
240
+ //
241
+ // This method configures the behavior of the match query when no terms remain after analysis
242
+ // (for example, if all terms are stop words). The specified zero_terms_query value determines
243
+ // how to handle this scenario, with options like "all" to match all documents or "none" to
244
+ // match none.
245
+ //
246
+ // Example usage:
247
+ //
248
+ // m := es.Match("title", "es-query-builder").ZeroTermsQuery(zerotermsquery.All)
249
+ // // m now has a "zero_terms_query" field set to "all" in the match query object.
250
+ //
251
+ // Parameters:
252
+ // - zeroTermsQuery: A zerotermsquery.ZeroTermsQuery value that specifies the behavior for zero-term queries.
253
+ //
254
+ // Returns:
255
+ //
256
+ // The updated matchType object with the "zero_terms_query" field set to the specified value.
257
+ func (m matchType ) ZeroTermsQuery (zeroTermsQuery ZeroTermsQuery.ZeroTermsQuery ) matchType {
258
+ return m .putInTheField ("zero_terms_query" , zeroTermsQuery )
259
+ }
0 commit comments