forked from aquasecurity/esquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_boosting.go
47 lines (41 loc) · 1.26 KB
/
query_boosting.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
package query
// BoostingQuery represents a compound query of type "boosting", as described in
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html
type BoostingQuery struct {
// Pos is the positive part of the query.
Pos Mappable
// Neg is the negative part of the query.
Neg Mappable
// NegBoost is the negative boost value.
NegBoost float32
}
// Boosting creates a new compound query of type "boosting".
func Boosting() *BoostingQuery {
return &BoostingQuery{}
}
// Positive sets the positive part of the boosting query.
func (q *BoostingQuery) Positive(p Mappable) *BoostingQuery {
q.Pos = p
return q
}
// Negative sets the negative part of the boosting query.
func (q *BoostingQuery) Negative(p Mappable) *BoostingQuery {
q.Neg = p
return q
}
// NegativeBoost sets the negative boost value.
func (q *BoostingQuery) NegativeBoost(b float32) *BoostingQuery {
q.NegBoost = b
return q
}
// Map returns a map representation of the boosting query, thus implementing
// the Mappable interface.
func (q *BoostingQuery) Map() map[string]interface{} {
return map[string]interface{}{
"boosting": map[string]interface{}{
"positive": q.Pos.Map(),
"negative": q.Neg.Map(),
"negative_boost": q.NegBoost,
},
}
}