@@ -260,24 +260,17 @@ func NewESEngine(mm message.Manager, cm channel.Manager, repo repository.Reposit
260
260
type searchQuery m
261
261
262
262
type searchBody struct {
263
- Query * struct {
264
- Bool * struct {
265
- Musts []searchQuery `json:"must,omitempty"`
266
- } `json:"bool,omitempty"`
267
- } `json:"query,omitempty"`
263
+ Query searchQuery `json:"query,omitempty"`
268
264
}
269
265
270
- func newSearchBody (sq []searchQuery ) searchBody {
271
- sb := searchBody {
272
- Query : & struct {
273
- Bool * struct {
274
- Musts []searchQuery `json:"must,omitempty"`
275
- } `json:"bool,omitempty"`
276
- }{Bool : & struct {
277
- Musts []searchQuery `json:"must,omitempty"`
278
- }{Musts : sq }},
266
+ func newSearchBody (andQueries []searchQuery ) searchBody {
267
+ return searchBody {
268
+ Query : searchQuery {
269
+ "bool" : boolQuery {
270
+ Must : andQueries ,
271
+ },
272
+ },
279
273
}
280
- return sb
281
274
}
282
275
283
276
type simpleQueryString struct {
@@ -286,6 +279,11 @@ type simpleQueryString struct {
286
279
DefaultOperator string `json:"default_operator"`
287
280
}
288
281
282
+ type boolQuery struct {
283
+ Must []searchQuery `json:"must,omitempty"`
284
+ Should []searchQuery `json:"should,omitempty"`
285
+ }
286
+
289
287
type rangeQuery map [string ]rangeParameters
290
288
291
289
type rangeParameters struct {
@@ -338,12 +336,34 @@ func (e *esEngine) Do(q *Query) (Result, error) {
338
336
musts = append (musts , searchQuery {"term" : termQuery {"isPublic" : termQueryParameter {Value : true }}})
339
337
}
340
338
341
- if q .To .Valid {
342
- musts = append (musts , searchQuery {"term" : termQuery {"to" : termQueryParameter {Value : q .To }}})
339
+ if len (q .To ) > 0 {
340
+ orQueries := make ([]searchQuery , 0 , len (q .To ))
341
+ for _ , toID := range q .To {
342
+ orQueries = append (orQueries , searchQuery {"term" : termQuery {"to" : termQueryParameter {Value : toID }}})
343
+ }
344
+
345
+ sq := searchQuery {"bool" : boolQuery {Should : orQueries }}
346
+ if len (q .To ) == 1 {
347
+ // OR検索が不要
348
+ sq = orQueries [0 ]
349
+ }
350
+
351
+ musts = append (musts , sq )
343
352
}
344
353
345
- if q .From .Valid {
346
- musts = append (musts , searchQuery {"term" : termQuery {"userId" : termQueryParameter {Value : q .From }}})
354
+ if len (q .From ) > 0 {
355
+ orQueries := make ([]searchQuery , 0 , len (q .From ))
356
+ for _ , fromID := range q .From {
357
+ orQueries = append (orQueries , searchQuery {"term" : termQuery {"userId" : termQueryParameter {Value : fromID }}})
358
+ }
359
+
360
+ sq := searchQuery {"bool" : boolQuery {Should : orQueries }}
361
+ if len (q .From ) == 1 {
362
+ // OR検索が不要
363
+ sq = orQueries [0 ]
364
+ }
365
+
366
+ musts = append (musts , sq )
347
367
}
348
368
349
369
if q .Citation .Valid {
0 commit comments