-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatch_phrase_prefix_query.go
150 lines (141 loc) · 5.89 KB
/
match_phrase_prefix_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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package es
import ZeroTermsQuery "github.com/Trendyol/es-query-builder/es/enums/zero-terms-query"
type matchPhrasePrefixType Object
// MatchPhrasePrefix creates a new es.matchPhrasePrefixType object with the specified field and query.
//
// This function initializes an es.matchPhrasePrefixType object for a match phrase prefix query, where the key
// is the field name and query is the value to search for in that field. This is used
// to construct queries that match the specified value in the given field.
//
// Example usage:
//
// m := es.MatchPhrasePrefix("title", "es-query-builder")
// // m now contains an es.matchPhrasePrefixType object that matches the query "es-query-builder" in the "title" field.
//
// Parameters:
// - key: A string representing the field name for the match phrase prefix query.
// - query: The value to be matched in the specified field. The type is generic.
//
// Returns:
//
// An es.matchPhrasePrefixType object containing the specified match phrase prefix query.
func MatchPhrasePrefix[T any](key string, query T) matchPhrasePrefixType {
return matchPhrasePrefixType{
"match_phrase_prefix": Object{
key: Object{
"query": query,
},
},
}
}
// Analyzer sets the "analyzer" field in the match phrase prefix query.
//
// This method specifies the analyzer to use for the match phrase prefix query, which determines
// how the input text is processed during analysis (e.g., tokenization and normalization).
// Custom analyzers can be used to tailor the query behavior to specific requirements.
//
// Example usage:
//
// m := es.MatchPhrasePrefix("title", "es-query-builder").Analyzer("custom_analyzer")
// // m now has an "analyzer" field set to "custom_analyzer" in the match phrase prefix query object.
//
// Parameters:
// - value: A string representing the name of the analyzer to use.
//
// Returns:
//
// The updated es.matchPhrasePrefixType object with the "analyzer" field set to the specified value.
func (m matchPhrasePrefixType) Analyzer(value string) matchPhrasePrefixType {
return m.putInTheField("analyzer", value)
}
// Boost sets the "boost" field in the match phrase prefix query.
//
// This method configures the match phrase prefix query to use a specified boost factor, which influences
// the relevance scoring of the matched documents.
//
// Example usage:
//
// m := es.MatchPhrasePrefix("title", "es-query-builder").Boost(1.5)
// // m now has a "boost" field set to 1.5 in the match phrase prefix query object.
//
// Parameters:
// - boost: A float64 value representing the boost factor to be applied to the match phrase prefix query.
//
// Returns:
//
// The updated es.matchPhrasePrefixType object with the "boost" field set to the specified value.
func (m matchPhrasePrefixType) Boost(boost float64) matchPhrasePrefixType {
return m.putInTheField("boost", boost)
}
// MaxExpansions sets the "max_expansions" field in the match phrase prefix query.
//
// This method configures the match phrase prefix query to limit the maximum number of terms that can be expanded
// for multi-term queries, such as those involving fuzzy matching. Higher values allow more terms to
// be considered, but may impact performance.
//
// Example usage:
//
// m := es.MatchPhrasePrefix("title", "es-query-builder").MaxExpansions(50)
// // m now has a "max_expansions" field set to 50 in the match phrase prefix query object.
//
// Parameters:
// - maxExpansions: An integer representing the maximum number of term expansions to be allowed in the match phrase prefix query.
//
// Returns:
//
// The updated es.matchPhrasePrefixType object with the "max_expansions" field set to the specified value.
func (m matchPhrasePrefixType) MaxExpansions(maxExpansions int) matchPhrasePrefixType {
return m.putInTheField("max_expansions", maxExpansions)
}
// ZeroTermsQuery sets the "zero_terms_query" field in the match phrase prefix query.
//
// This method configures the behavior of the match phrase prefix query when no terms remain after analysis
// (for example, if all terms are stop words). The specified zero_terms_query value determines
// how to handle this scenario, with options like "all" to match all documents or "none" to
// match none.
//
// Example usage:
//
// m := es.MatchPhrasePrefix("title", "es-query-builder").ZeroTermsQuery(zerotermsquery.All)
// // m now has a "zero_terms_query" field set to "all" in the match phrase prefix query object.
//
// Parameters:
// - zeroTermsQuery: A zerotermsquery.ZeroTermsQuery value that specifies the behavior for zero-term queries.
//
// Returns:
//
// The updated es.matchPhrasePrefixType object with the "zero_terms_query" field set to the specified value.
func (m matchPhrasePrefixType) ZeroTermsQuery(zeroTermsQuery ZeroTermsQuery.ZeroTermsQuery) matchPhrasePrefixType {
return m.putInTheField("zero_terms_query", zeroTermsQuery)
}
// Slop sets the "slop" field in the match phrase prefix query.
//
// This method specifies the allowed distance between terms in a phrase query, enabling more
// flexibility in matching phrases that may have slight variations in word order or spacing.
// A higher slop value allows more variation, while a slop of 0 requires exact matching.
//
// Example usage:
//
// m := es.MatchPhrasePrefix("title", "es-query-builder").Slop(2)
// // m now has a "slop" field set to 2 in the match phrase prefix query object.
//
// Parameters:
// - slop: An integer representing the maximum allowed distance between terms.
//
// Returns:
//
// The updated es.matchPhrasePrefixType object with the "slop" field set to the specified value.
func (m matchPhrasePrefixType) Slop(slop int) matchPhrasePrefixType {
return m.putInTheField("slop", slop)
}
func (m matchPhrasePrefixType) putInTheField(key string, value any) matchPhrasePrefixType {
if matchPhrasePrefix, ok := m["match_phrase_prefix"].(Object); ok {
for _, fieldObj := range matchPhrasePrefix {
if fieldObject, foOk := fieldObj.(Object); foOk {
fieldObject[key] = value
break
}
}
}
return m
}