Skip to content

Commit

Permalink
Add support for function score on query dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
kytrinyx committed Apr 7, 2015
1 parent 0e8e430 commit 95e96e7
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/searchquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ type QueryDsl struct {

// The core Query Syntax can be embedded as a child of a variety of different parents
type QueryEmbed struct {
MatchAll *MatchAll `json:"match_all,omitempty"`
Terms map[string]string `json:"term,omitempty"`
Qs *QueryString `json:"query_string,omitempty"`
MultiMatch *MultiMatch `json:"multi_match,omitempty"`
MatchAll *MatchAll `json:"match_all,omitempty"`
Terms map[string]string `json:"term,omitempty"`
Qs *QueryString `json:"query_string,omitempty"`
MultiMatch *MultiMatch `json:"multi_match,omitempty"`
FunctionScore map[string]interface{} `json:"function_score,omitempty"`
//Exist string `json:"_exists_,omitempty"`
}

Expand Down Expand Up @@ -118,6 +119,16 @@ func (q *QueryDsl) Term(name, value string) *QueryDsl {
return q
}

// FunctionScore sets functions to use to score the documents.
// http://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-function-score-query.html
func (q *QueryDsl) FunctionScore(mode string, functions ...map[string]interface{}) *QueryDsl {
q.QueryEmbed.FunctionScore = map[string]interface{}{
"functions": functions,
"score_mode": mode,
}
return q
}

// The raw search strings (lucene valid)
func (q *QueryDsl) Search(searchFor string) *QueryDsl {
//I don't think this is right, it is not a filter.query, it should be q query?
Expand Down

0 comments on commit 95e96e7

Please sign in to comment.