esquery/constant_score.go
Ido Perlmuter 6c8e71c188 Add support for compound queries
This commit adds support for the compound queries "bool", "boosting",
"constant_score" and "dis_max". The "function_score" query is not
supported yet.

Compound queries are simple. They act just like simple queries, except
that they are recursive, wrapping other simple/compound queries.

For example:

    esquery.Bool().
        Must(Term("user", "kimchy"), Term("author", "kimchy")).
        Filter(Term("tag", "tech"))
2020-02-20 11:50:11 +02:00

30 lines
625 B
Go

package esquery
import "encoding/json"
type ConstantScoreQuery struct {
params constantScoreParams
}
type constantScoreParams struct {
Filter json.Marshaler `json:"filter"`
Boost float32 `json:"boost,omitempty"`
}
func ConstantScore(filter json.Marshaler) *ConstantScoreQuery {
return &ConstantScoreQuery{
params: constantScoreParams{Filter: filter},
}
}
func (q *ConstantScoreQuery) Boost(b float32) *ConstantScoreQuery {
q.params.Boost = b
return q
}
func (q ConstantScoreQuery) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]constantScoreParams{
"constant_score": q.params,
})
}