diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-06-21 19:06:17 -0700 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-06-21 19:06:17 -0700 |
commit | 42f28ab8e374137fe3f5d25424489d879d4724f8 (patch) | |
tree | 20353f2446b506d32e6d353b72a57bf48f070389 /vendor/gopkg.in/olivere/elastic.v5/suggester_context_category.go | |
parent | 6b39c308d882a0aeac533f8ab1d90b48a2ae4b5a (diff) | |
download | chat-42f28ab8e374137fe3f5d25424489d879d4724f8.tar.gz chat-42f28ab8e374137fe3f5d25424489d879d4724f8.tar.bz2 chat-42f28ab8e374137fe3f5d25424489d879d4724f8.zip |
Updating server dependancies (#6712)
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/suggester_context_category.go')
-rw-r--r-- | vendor/gopkg.in/olivere/elastic.v5/suggester_context_category.go | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/suggester_context_category.go b/vendor/gopkg.in/olivere/elastic.v5/suggester_context_category.go index c224ae04a..2d63fe8fb 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/suggester_context_category.go +++ b/vendor/gopkg.in/olivere/elastic.v5/suggester_context_category.go @@ -62,23 +62,36 @@ func (q *SuggesterCategoryMapping) Source() (interface{}, error) { // See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/suggester-context.html#_category_query. type SuggesterCategoryQuery struct { name string - values []string + values map[string]*int } // NewSuggesterCategoryQuery creates a new SuggesterCategoryQuery. func NewSuggesterCategoryQuery(name string, values ...string) *SuggesterCategoryQuery { q := &SuggesterCategoryQuery{ name: name, - values: make([]string, 0), + values: make(map[string]*int), } + if len(values) > 0 { - q.values = append(q.values, values...) + q.Values(values...) } return q } +func (q *SuggesterCategoryQuery) Value(val string) *SuggesterCategoryQuery { + q.values[val] = nil + return q +} + +func (q *SuggesterCategoryQuery) ValueWithBoost(val string, boost int) *SuggesterCategoryQuery { + q.values[val] = &boost + return q +} + func (q *SuggesterCategoryQuery) Values(values ...string) *SuggesterCategoryQuery { - q.values = append(q.values, values...) + for _, val := range values { + q.values[val] = nil + } return q } @@ -88,11 +101,18 @@ func (q *SuggesterCategoryQuery) Source() (interface{}, error) { switch len(q.values) { case 0: - source[q.name] = q.values - case 1: - source[q.name] = q.values[0] + source[q.name] = make([]string, 0) default: - source[q.name] = q.values + contexts := make([]interface{}, 0) + for val, boost := range q.values { + context := make(map[string]interface{}) + context["context"] = val + if boost != nil { + context["boost"] = *boost + } + contexts = append(contexts, context) + } + source[q.name] = contexts } return source, nil |