forked from defensestation/osquery
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_script_score.go
More file actions
51 lines (44 loc) · 1.48 KB
/
query_script_score.go
File metadata and controls
51 lines (44 loc) · 1.48 KB
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
// Modified by Sushmita on 2025-01-31
// Changes: Added script score query support
package osquery
import "github.com/fatih/structs"
// ScriptScoreQuery represents a compound query of type "script_score", as
// described in
// https://opensearch.org/docs/latest/query-dsl/specialized/script-score/
type ScriptScoreQuery struct {
query Mappable
script ScriptField
minScore float32
boost float32
}
// ScriptScore creates a new query of type "script_score" with the provided
// query and script.
func ScriptScore(query Mappable, script *ScriptField) *ScriptScoreQuery {
return &ScriptScoreQuery{
query: query,
script: *script,
}
}
// Boost sets the boost value of the query.
func (q *ScriptScoreQuery) Boost(b float32) *ScriptScoreQuery {
q.boost = b
return q
}
// MinScore sets the minimum score of the query.
func (q *ScriptScoreQuery) MinScore(min float32) *ScriptScoreQuery {
q.minScore = min
return q
}
// Map returns a map representation of the query, thus implementing the
// Mappable interface.
func (q *ScriptScoreQuery) Map() map[string]interface{} {
script := q.script.Map()["script"].(map[string]interface{})
return map[string]interface{}{
"script_score": structs.Map(struct {
Query map[string]interface{} `structs:"query"`
Script map[string]interface{} `structs:"script"`
Boost float32 `structs:"boost,omitempty"`
MinScore float32 `structs:"min_score,omitempty"`
}{q.query.Map(), script, q.boost, q.minScore}),
}
}