-
Notifications
You must be signed in to change notification settings - Fork 0
/
srv_search_boosting.go
54 lines (41 loc) · 981 Bytes
/
srv_search_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
48
49
50
51
52
53
54
package elastic
import "encoding/json"
type Boosting struct {
mappings map[string]interface{}
}
func NewBoosting() *Boosting {
new := &Boosting{
mappings: make(map[string]interface{}),
}
return new
}
func (b *Boosting) Positive(value ...Query) *Boosting {
if len(value) > 0 {
b.mappings["positive"] = append(b.mappings["positive"].([]Query), value...)
}
return b
}
func (b *Boosting) Negative(value ...Query) *Boosting {
if len(value) > 0 {
b.mappings["negative"] = append(b.mappings["negative"].([]Query), value...)
}
return b
}
func (b *Boosting) NegativeBoost(value float64) *Boosting {
b.mappings["negative_boost"] = value
return b
}
func (b *Boosting) Data() interface{} {
data := make(map[string]interface{})
if len(b.mappings) > 0 {
data["boosting"] = b.mappings
}
return data
}
func (b *Boosting) Bytes() []byte {
bytes, _ := json.Marshal(b.Data())
return bytes
}
func (b *Boosting) String() string {
return string(b.Bytes())
}