0
0

Added missing boost getters

This commit is contained in:
slavikm 2016-11-22 12:50:08 -08:00
parent 187d6013df
commit a4c94e440e
18 changed files with 132 additions and 43 deletions

View File

@ -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) {

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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)

View File

@ -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)

View File

@ -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) {

View File

@ -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) {

View File

@ -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
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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 == "" {