forked from aquasecurity/esquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ranking.go
57 lines (48 loc) · 1.09 KB
/
ranking.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
package query
func RankFeature(field string, rankFeatureType RankFeatureTypeInterface) *RankFeatureQuery {
return &RankFeatureQuery{
field: field,
rankFeatureType: rankFeatureType,
}
}
type RankFeatureQuery struct {
rankFeatureType RankFeatureTypeInterface
boost *float64
field string
}
func (r *RankFeatureQuery) Map() map[string]any {
rankFeature := map[string]any{
"field": r.field,
"log": r.rankFeatureType.Map(),
"boost": 1,
}
m := map[string]any{
"rank_feature": rankFeature,
}
if r.boost != nil {
rankFeature["boost"] = *r.boost
}
return m
}
func (r *RankFeatureQuery) Boost(b float64) *RankFeatureQuery {
r.boost = &b
return r
}
type RankFeatureTypeInterface interface {
RankFeatureTypeInterface()
Map() map[string]any
}
type LogQuery struct {
scalingFactor float64
}
func (l *LogQuery) RankFeatureTypeInterface() {}
func (l *LogQuery) Map() map[string]interface{} {
return map[string]any{
"scaling_factor": l.scalingFactor,
}
}
func Log(scalingFactor float64) *LogQuery {
return &LogQuery{
scalingFactor: scalingFactor,
}
}