From a4c94e440e98b8e444d4b8f07692f57bac74eb26 Mon Sep 17 00:00:00 2001 From: slavikm Date: Tue, 22 Nov 2016 12:50:08 -0800 Subject: [PATCH] Added missing boost getters --- search/query/bool_field.go | 5 ++++- search/query/boolean.go | 19 +++++++++++++------ search/query/conjunction.go | 13 ++++++++++--- search/query/date_range.go | 5 ++++- search/query/disjunction.go | 14 +++++++++++--- search/query/docid.go | 15 +++++++++++---- search/query/fuzzy.go | 5 ++++- search/query/match.go | 5 ++++- search/query/match_all.go | 17 +++++++++++++---- search/query/match_none.go | 13 ++++++++++--- search/query/match_phrase.go | 5 ++++- search/query/numeric_range.go | 5 ++++- search/query/phrase.go | 15 +++++++++++---- search/query/prefix.go | 5 ++++- search/query/query_string.go | 13 ++++++++++--- search/query/regexp.go | 5 ++++- search/query/term.go | 5 ++++- search/query/wildcard.go | 11 +++++++---- 18 files changed, 132 insertions(+), 43 deletions(-) diff --git a/search/query/bool_field.go b/search/query/bool_field.go index 1640af6c..be109fc4 100644 --- a/search/query/bool_field.go +++ b/search/query/bool_field.go @@ -40,7 +40,10 @@ func (q *BoolFieldQuery) SetBoost(b float64) { } func (q *BoolFieldQuery) Boost() float64{ - return q.BoostVal.Value() + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *BoolFieldQuery) SetField(f string) { diff --git a/search/query/boolean.go b/search/query/boolean.go index ea7f5dec..902bf66c 100644 --- a/search/query/boolean.go +++ b/search/query/boolean.go @@ -25,10 +25,10 @@ import ( ) type BooleanQuery struct { - Must Query `json:"must,omitempty"` - Should Query `json:"should,omitempty"` - MustNot Query `json:"must_not,omitempty"` - Boost *Boost `json:"boost,omitempty"` + Must Query `json:"must,omitempty"` + Should Query `json:"should,omitempty"` + MustNot Query `json:"must_not,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` } // NewBooleanQuery creates a compound Query composed @@ -90,7 +90,14 @@ func (q *BooleanQuery) AddMustNot(m ...Query) { func (q *BooleanQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *BooleanQuery) Boost() float64{ + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *BooleanQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { @@ -199,7 +206,7 @@ func (q *BooleanQuery) UnmarshalJSON(data []byte) error { } } - q.Boost = tmp.Boost + q.BoostVal = tmp.Boost return nil } diff --git a/search/query/conjunction.go b/search/query/conjunction.go index e48b379b..125807f3 100644 --- a/search/query/conjunction.go +++ b/search/query/conjunction.go @@ -25,7 +25,7 @@ import ( type ConjunctionQuery struct { Conjuncts []Query `json:"conjuncts"` - Boost *Boost `json:"boost,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` } // NewConjunctionQuery creates a new compound Query. @@ -38,7 +38,14 @@ func NewConjunctionQuery(conjuncts []Query) *ConjunctionQuery { func (q *ConjunctionQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *ConjunctionQuery) Boost() float64{ + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *ConjunctionQuery) AddQuery(aq ...Query) { @@ -93,6 +100,6 @@ func (q *ConjunctionQuery) UnmarshalJSON(data []byte) error { } q.Conjuncts[i] = query } - q.Boost = tmp.Boost + q.BoostVal = tmp.Boost return nil } diff --git a/search/query/date_range.go b/search/query/date_range.go index 8c5811f1..fb6f9efc 100644 --- a/search/query/date_range.go +++ b/search/query/date_range.go @@ -114,7 +114,10 @@ func (q *DateRangeQuery) SetBoost(b float64) { } func (q *DateRangeQuery) Boost() float64{ - return q.BoostVal.Value() + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } diff --git a/search/query/disjunction.go b/search/query/disjunction.go index b4b8575e..ed8e1400 100644 --- a/search/query/disjunction.go +++ b/search/query/disjunction.go @@ -26,7 +26,7 @@ import ( type DisjunctionQuery struct { Disjuncts []Query `json:"disjuncts"` - Boost *Boost `json:"boost,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` Min float64 `json:"min"` } @@ -40,9 +40,17 @@ func NewDisjunctionQuery(disjuncts []Query) *DisjunctionQuery { func (q *DisjunctionQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost } +func (q *DisjunctionQuery) Boost() float64{ + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 +} + + func (q *DisjunctionQuery) AddQuery(aq ...Query) { for _, aaq := range aq { q.Disjuncts = append(q.Disjuncts, aaq) @@ -103,7 +111,7 @@ func (q *DisjunctionQuery) UnmarshalJSON(data []byte) error { } q.Disjuncts[i] = query } - q.Boost = tmp.Boost + q.BoostVal = tmp.Boost q.Min = tmp.Min return nil } diff --git a/search/query/docid.go b/search/query/docid.go index 3bf372b8..9d52a53a 100644 --- a/search/query/docid.go +++ b/search/query/docid.go @@ -22,8 +22,8 @@ import ( ) type DocIDQuery struct { - IDs []string `json:"ids"` - Boost *Boost `json:"boost,omitempty"` + IDs []string `json:"ids"` + BoostVal *Boost `json:"boost,omitempty"` } // NewDocIDQuery creates a new Query object returning indexed documents among @@ -37,9 +37,16 @@ func NewDocIDQuery(ids []string) *DocIDQuery { func (q *DocIDQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *DocIDQuery) Boost() float64{ + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *DocIDQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { - return searcher.NewDocIDSearcher(i, q.IDs, q.Boost.Value(), explain) + return searcher.NewDocIDSearcher(i, q.IDs, q.BoostVal.Value(), explain) } diff --git a/search/query/fuzzy.go b/search/query/fuzzy.go index 6effd343..1973b14d 100644 --- a/search/query/fuzzy.go +++ b/search/query/fuzzy.go @@ -49,7 +49,10 @@ func (q *FuzzyQuery) SetBoost(b float64) { } func (q *FuzzyQuery) Boost() float64{ - return q.BoostVal.Value() + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *FuzzyQuery) SetField(f string) { diff --git a/search/query/match.go b/search/query/match.go index 6d0b0053..da544163 100644 --- a/search/query/match.go +++ b/search/query/match.go @@ -91,7 +91,10 @@ func (q *MatchQuery) SetBoost(b float64) { } func (q *MatchQuery) Boost() float64{ - return q.BoostVal.Value() + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *MatchQuery) SetField(f string) { diff --git a/search/query/match_all.go b/search/query/match_all.go index d33e2bb2..601455bb 100644 --- a/search/query/match_all.go +++ b/search/query/match_all.go @@ -24,7 +24,7 @@ import ( ) type MatchAllQuery struct { - Boost *Boost `json:"boost,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` } // NewMatchAllQuery creates a Query which will @@ -35,16 +35,25 @@ func NewMatchAllQuery() *MatchAllQuery { func (q *MatchAllQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost } +func (q *MatchAllQuery) Boost() float64{ + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 +} + + + func (q *MatchAllQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { - return searcher.NewMatchAllSearcher(i, q.Boost.Value(), explain) + return searcher.NewMatchAllSearcher(i, q.BoostVal.Value(), explain) } func (q *MatchAllQuery) MarshalJSON() ([]byte, error) { tmp := map[string]interface{}{ - "boost": q.Boost, + "boost": q.BoostVal, "match_all": map[string]interface{}{}, } return json.Marshal(tmp) diff --git a/search/query/match_none.go b/search/query/match_none.go index ccc5d5f7..34391674 100644 --- a/search/query/match_none.go +++ b/search/query/match_none.go @@ -24,7 +24,7 @@ import ( ) type MatchNoneQuery struct { - Boost *Boost `json:"boost,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` } // NewMatchNoneQuery creates a Query which will not @@ -35,7 +35,14 @@ func NewMatchNoneQuery() *MatchNoneQuery { func (q *MatchNoneQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *MatchNoneQuery) Boost() float64{ + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *MatchNoneQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { @@ -44,7 +51,7 @@ func (q *MatchNoneQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, e func (q *MatchNoneQuery) MarshalJSON() ([]byte, error) { tmp := map[string]interface{}{ - "boost": q.Boost, + "boost": q.BoostVal, "match_none": map[string]interface{}{}, } return json.Marshal(tmp) diff --git a/search/query/match_phrase.go b/search/query/match_phrase.go index a148808f..bd03c1b6 100644 --- a/search/query/match_phrase.go +++ b/search/query/match_phrase.go @@ -50,7 +50,10 @@ func (q *MatchPhraseQuery) SetBoost(b float64) { } func (q *MatchPhraseQuery) Boost() float64{ - return q.BoostVal.Value() + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *MatchPhraseQuery) SetField(f string) { diff --git a/search/query/numeric_range.go b/search/query/numeric_range.go index 93f7fd6b..6fffa642 100644 --- a/search/query/numeric_range.go +++ b/search/query/numeric_range.go @@ -60,7 +60,10 @@ func (q *NumericRangeQuery) SetBoost(b float64) { } func (q *NumericRangeQuery) Boost() float64{ - return q.BoostVal.Value() + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *NumericRangeQuery) SetField(f string) { diff --git a/search/query/phrase.go b/search/query/phrase.go index 2d382bbd..0ab8f575 100644 --- a/search/query/phrase.go +++ b/search/query/phrase.go @@ -27,7 +27,7 @@ import ( type PhraseQuery struct { Terms []string `json:"terms"` Field string `json:"field,omitempty"` - Boost *Boost `json:"boost,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` termQueries []Query } @@ -55,7 +55,14 @@ func NewPhraseQuery(terms []string, field string) *PhraseQuery { func (q *PhraseQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *PhraseQuery) Boost() float64{ + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *PhraseQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { @@ -84,10 +91,10 @@ func (q *PhraseQuery) UnmarshalJSON(data []byte) error { } q.Terms = tmp.Terms q.Field = tmp.Field - q.Boost = tmp.Boost + q.BoostVal = tmp.BoostVal q.termQueries = make([]Query, len(q.Terms)) for i, term := range q.Terms { - q.termQueries[i] = &TermQuery{Term: term, FieldVal: q.Field, BoostVal: q.Boost} + q.termQueries[i] = &TermQuery{Term: term, FieldVal: q.Field, BoostVal: q.BoostVal} } return nil } diff --git a/search/query/prefix.go b/search/query/prefix.go index d8c2bb2f..5c013862 100644 --- a/search/query/prefix.go +++ b/search/query/prefix.go @@ -42,7 +42,10 @@ func (q *PrefixQuery) SetBoost(b float64) { } func (q *PrefixQuery) Boost() float64{ - return q.BoostVal.Value() + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *PrefixQuery) SetField(f string) { diff --git a/search/query/query_string.go b/search/query/query_string.go index 1e2785d7..366cce04 100644 --- a/search/query/query_string.go +++ b/search/query/query_string.go @@ -21,8 +21,8 @@ import ( ) type QueryStringQuery struct { - Query string `json:"query"` - Boost *Boost `json:"boost,omitempty"` + Query string `json:"query"` + BoostVal *Boost `json:"boost,omitempty"` } // NewQueryStringQuery creates a new Query used for @@ -36,7 +36,14 @@ func NewQueryStringQuery(query string) *QueryStringQuery { func (q *QueryStringQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *QueryStringQuery) Boost() float64{ + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *QueryStringQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { diff --git a/search/query/regexp.go b/search/query/regexp.go index 21d29b71..070c4026 100644 --- a/search/query/regexp.go +++ b/search/query/regexp.go @@ -46,7 +46,10 @@ func (q *RegexpQuery) SetBoost(b float64) { } func (q *RegexpQuery) Boost() float64{ - return q.BoostVal.Value() + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *RegexpQuery) SetField(f string) { diff --git a/search/query/term.go b/search/query/term.go index 0e939ad3..a12a610e 100644 --- a/search/query/term.go +++ b/search/query/term.go @@ -41,7 +41,10 @@ func (q *TermQuery) SetBoost(b float64) { } func (q *TermQuery) Boost() float64{ - return q.BoostVal.Value() + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 } func (q *TermQuery) SetField(f string) { diff --git a/search/query/wildcard.go b/search/query/wildcard.go index e2adc24b..5ed420f4 100644 --- a/search/query/wildcard.go +++ b/search/query/wildcard.go @@ -66,6 +66,13 @@ func (q *WildcardQuery) SetBoost(b float64) { q.BoostVal = &boost } +func (q *WildcardQuery) Boost() float64{ + if q.BoostVal != nil { + return q.BoostVal.Value() + } + return 0 +} + func (q *WildcardQuery) SetField(f string) { q.FieldVal = f } @@ -74,10 +81,6 @@ func (q *WildcardQuery) Field() string{ return q.FieldVal } -func (q *WildcardQuery) Boost() float64{ - return q.BoostVal.Value() -} - func (q *WildcardQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { field := q.FieldVal if q.FieldVal == "" {