Debian Codegraph @

search_queries_match_all.go

raw
1 // Copyright 2012-present Oliver Eilhard. All rights reserved.
2 // Use of this source code is governed by a MIT-license.
3 // See http://olivere.mit-license.org/license.txt for details.
4
5 package elastic
6
7 // MatchAllQuery is the most simple query, which matches all documents,
8 // giving them all a _score of 1.0.
9 //
10 // For more details, see
11 // https://www.elastic.co/guide/en/elasticsearch/reference/5.2/query-dsl-match-all-query.html
12 type MatchAllQuery struct {
13 boost *float64
14 queryName string
15 }
16
17 // NewMatchAllQuery creates and initializes a new match all query.
18 func NewMatchAllQuery() *MatchAllQuery {
19 return &MatchAllQuery{}
20 }
21
22 // Boost sets the boost for this query. Documents matching this query will
23 // (in addition to the normal weightings) have their score multiplied by the
24 // boost provided.
25 func (q *MatchAllQuery) Boost(boost float64) *MatchAllQuery {
26 q.boost = &boost
27 return q
28 }
29
30 // QueryName sets the query name.
31 func (q *MatchAllQuery) QueryName(name string) *MatchAllQuery {
32 q.queryName = name
33 return q
34 }
35
36 // Source returns JSON for the match all query.
37 func (q MatchAllQuery) Source() (interface{}, error) {
38 // {
39 // "match_all" : { ... }
40 // }
41 source := make(map[string]interface{})
42 params := make(map[string]interface{})
43 source["match_all"] = params
44 if q.boost != nil {
45 params["boost"] = *q.boost
46 }
47 if q.queryName != "" {
48 params["_name"] = q.queryName
49 }
50 return source, nil
51 }