@@ -20,6 +20,12 @@ func TestIntervalQuery_Integration(t *testing.T) {
20
20
t .Run ("Prefix" , func (t * testing.T ) {
21
21
testIntervalQueryPrefix (client , t )
22
22
})
23
+ t .Run ("Wildcard" , func (t * testing.T ) {
24
+ testIntervalQueryWildcard (client , t )
25
+ })
26
+ t .Run ("Fuzzy" , func (t * testing.T ) {
27
+ testIntervalQueryFuzzy (client , t )
28
+ })
23
29
}
24
30
25
31
func testIntervalQueryMatch (client * Client , t * testing.T ) {
@@ -115,3 +121,97 @@ func testIntervalQueryPrefix(client *Client, t *testing.T) {
115
121
}
116
122
}
117
123
}
124
+
125
+ func testIntervalQueryWildcard (client * Client , t * testing.T ) {
126
+ q := NewIntervalQuery (
127
+ "message" ,
128
+ NewIntervalQueryRuleAllOf (
129
+ NewIntervalQueryRuleAnyOf (
130
+ NewIntervalQueryRuleMatch ("Golang" ).Ordered (true ),
131
+ NewIntervalQueryRuleMatch ("Cycling" ).MaxGaps (0 ).Filter (
132
+ NewIntervalQueryFilter ().NotContaining (
133
+ NewIntervalQueryRuleWildcard ("Hockey*" ),
134
+ ),
135
+ ),
136
+ ),
137
+ ).Ordered (true ),
138
+ )
139
+
140
+ // Match all should return all documents
141
+ searchResult , err := client .Search ().
142
+ Index (testIndexName ).
143
+ Query (q ).
144
+ Size (10 ).
145
+ Pretty (true ).
146
+ Do (context .TODO ())
147
+ if err != nil {
148
+ t .Fatal (err )
149
+ }
150
+ if searchResult .Hits == nil {
151
+ t .Errorf ("expected SearchResult.Hits != nil; got nil" )
152
+ }
153
+ if got , want := searchResult .TotalHits (), int64 (2 ); got != want {
154
+ t .Errorf ("expected SearchResult.TotalHits() = %d; got %d" , want , got )
155
+ }
156
+ if got , want := len (searchResult .Hits .Hits ), 2 ; got != want {
157
+ t .Errorf ("expected len(SearchResult.Hits.Hits) = %d; got %d" , want , got )
158
+ }
159
+
160
+ for _ , hit := range searchResult .Hits .Hits {
161
+ if hit .Index != testIndexName {
162
+ t .Errorf ("expected SearchResult.Hits.Hit.Index = %q; got %q" , testIndexName , hit .Index )
163
+ }
164
+ item := make (map [string ]interface {})
165
+ err := json .Unmarshal (hit .Source , & item )
166
+ if err != nil {
167
+ t .Fatal (err )
168
+ }
169
+ }
170
+ }
171
+
172
+ func testIntervalQueryFuzzy (client * Client , t * testing.T ) {
173
+ q := NewIntervalQuery (
174
+ "message" ,
175
+ NewIntervalQueryRuleAllOf (
176
+ NewIntervalQueryRuleAnyOf (
177
+ NewIntervalQueryRuleMatch ("Golang" ).Ordered (true ),
178
+ NewIntervalQueryRuleMatch ("Cycling" ).MaxGaps (0 ).Filter (
179
+ NewIntervalQueryFilter ().NotContaining (
180
+ NewIntervalQueryRuleFuzzy ("Hocky" ).Fuzziness ("auto" ),
181
+ ),
182
+ ),
183
+ ),
184
+ ).Ordered (true ),
185
+ )
186
+
187
+ // Match all should return all documents
188
+ searchResult , err := client .Search ().
189
+ Index (testIndexName ).
190
+ Query (q ).
191
+ Size (10 ).
192
+ Pretty (true ).
193
+ Do (context .TODO ())
194
+ if err != nil {
195
+ t .Fatal (err )
196
+ }
197
+ if searchResult .Hits == nil {
198
+ t .Errorf ("expected SearchResult.Hits != nil; got nil" )
199
+ }
200
+ if got , want := searchResult .TotalHits (), int64 (2 ); got != want {
201
+ t .Errorf ("expected SearchResult.TotalHits() = %d; got %d" , want , got )
202
+ }
203
+ if got , want := len (searchResult .Hits .Hits ), 2 ; got != want {
204
+ t .Errorf ("expected len(SearchResult.Hits.Hits) = %d; got %d" , want , got )
205
+ }
206
+
207
+ for _ , hit := range searchResult .Hits .Hits {
208
+ if hit .Index != testIndexName {
209
+ t .Errorf ("expected SearchResult.Hits.Hit.Index = %q; got %q" , testIndexName , hit .Index )
210
+ }
211
+ item := make (map [string ]interface {})
212
+ err := json .Unmarshal (hit .Source , & item )
213
+ if err != nil {
214
+ t .Fatal (err )
215
+ }
216
+ }
217
+ }
0 commit comments