diff --git a/search/query/bool_field.go b/search/query/bool_field.go index 926ad96d..1640af6c 100644 --- a/search/query/bool_field.go +++ b/search/query/bool_field.go @@ -23,8 +23,8 @@ import ( type BoolFieldQuery struct { Bool bool `json:"bool"` - Field string `json:"field,omitempty"` - Boost *Boost `json:"boost,omitempty"` + FieldVal string `json:"field,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` } // NewBoolFieldQuery creates a new Query for boolean fields @@ -36,30 +36,30 @@ func NewBoolFieldQuery(val bool) *BoolFieldQuery { func (q *BoolFieldQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *BoolFieldQuery) Boost() float64{ + return q.BoostVal.Value() } func (q *BoolFieldQuery) SetField(f string) { - q.Field = f + q.FieldVal = f } -func (q *BoolFieldQuery) GetField() string{ - return q.Field -} - -func (q *BoolFieldQuery) GetBoost() float64{ - return q.Boost.Value() +func (q *BoolFieldQuery) Field() string{ + return q.FieldVal } func (q *BoolFieldQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { - field := q.Field - if q.Field == "" { + field := q.FieldVal + if q.FieldVal == "" { field = m.DefaultSearchField() } term := "F" if q.Bool { term = "T" } - return searcher.NewTermSearcher(i, term, field, q.Boost.Value(), explain) + return searcher.NewTermSearcher(i, term, field, q.BoostVal.Value(), explain) } diff --git a/search/query/date_range.go b/search/query/date_range.go index 994588f3..8c5811f1 100644 --- a/search/query/date_range.go +++ b/search/query/date_range.go @@ -80,8 +80,8 @@ type DateRangeQuery struct { End BleveQueryTime `json:"end,omitempty"` InclusiveStart *bool `json:"inclusive_start,omitempty"` InclusiveEnd *bool `json:"inclusive_end,omitempty"` - Field string `json:"field,omitempty"` - Boost *Boost `json:"boost,omitempty"` + FieldVal string `json:"field,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` } // NewDateRangeQuery creates a new Query for ranges @@ -110,19 +110,20 @@ func NewDateRangeInclusiveQuery(start, end time.Time, startInclusive, endInclusi func (q *DateRangeQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost } +func (q *DateRangeQuery) Boost() float64{ + return q.BoostVal.Value() +} + + func (q *DateRangeQuery) SetField(f string) { - q.Field = f + q.FieldVal = f } -func (q *DateRangeQuery) GetField() string{ - return q.Field -} - -func (q *DateRangeQuery) GetBoost() float64{ - return q.Boost.Value() +func (q *DateRangeQuery) Field() string{ + return q.FieldVal } func (q *DateRangeQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { @@ -131,12 +132,12 @@ func (q *DateRangeQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, e return nil, err } - field := q.Field - if q.Field == "" { + field := q.FieldVal + if q.FieldVal == "" { field = m.DefaultSearchField() } - return searcher.NewNumericRangeSearcher(i, min, max, q.InclusiveStart, q.InclusiveEnd, field, q.Boost.Value(), explain) + return searcher.NewNumericRangeSearcher(i, min, max, q.InclusiveStart, q.InclusiveEnd, field, q.BoostVal.Value(), explain) } func (q *DateRangeQuery) parseEndpoints() (*float64, *float64, error) { diff --git a/search/query/fuzzy.go b/search/query/fuzzy.go index ee1f4058..6effd343 100644 --- a/search/query/fuzzy.go +++ b/search/query/fuzzy.go @@ -25,8 +25,8 @@ type FuzzyQuery struct { Term string `json:"term"` Prefix int `json:"prefix_length"` Fuzziness int `json:"fuzziness"` - Field string `json:"field,omitempty"` - Boost *Boost `json:"boost,omitempty"` + FieldVal string `json:"field,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` } // NewFuzzyQuery creates a new Query which finds @@ -45,19 +45,19 @@ func NewFuzzyQuery(term string) *FuzzyQuery { func (q *FuzzyQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *FuzzyQuery) Boost() float64{ + return q.BoostVal.Value() } func (q *FuzzyQuery) SetField(f string) { - q.Field = f + q.FieldVal = f } -func (q *FuzzyQuery) GetField() string{ - return q.Field -} - -func (q *FuzzyQuery) GetBoost() float64{ - return q.Boost.Value() +func (q *FuzzyQuery) Field() string{ + return q.FieldVal } func (q *FuzzyQuery) SetFuzziness(f int) { @@ -69,9 +69,9 @@ func (q *FuzzyQuery) SetPrefix(p int) { } func (q *FuzzyQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { - field := q.Field - if q.Field == "" { + field := q.FieldVal + if q.FieldVal == "" { field = m.DefaultSearchField() } - return searcher.NewFuzzySearcher(i, q.Term, q.Prefix, q.Fuzziness, field, q.Boost.Value(), explain) + return searcher.NewFuzzySearcher(i, q.Term, q.Prefix, q.Fuzziness, field, q.BoostVal.Value(), explain) } diff --git a/search/query/match.go b/search/query/match.go index 0d1a2a3c..6d0b0053 100644 --- a/search/query/match.go +++ b/search/query/match.go @@ -25,9 +25,9 @@ import ( type MatchQuery struct { Match string `json:"match"` - Field string `json:"field,omitempty"` + FieldVal string `json:"field,omitempty"` Analyzer string `json:"analyzer,omitempty"` - Boost *Boost `json:"boost,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` Prefix int `json:"prefix_length"` Fuzziness int `json:"fuzziness"` Operator MatchQueryOperator `json:"operator,omitempty"` @@ -87,19 +87,19 @@ func NewMatchQuery(match string) *MatchQuery { func (q *MatchQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *MatchQuery) Boost() float64{ + return q.BoostVal.Value() } func (q *MatchQuery) SetField(f string) { - q.Field = f + q.FieldVal = f } -func (q *MatchQuery) GetField() string{ - return q.Field -} - -func (q *MatchQuery) GetBoost() float64{ - return q.Boost.Value() +func (q *MatchQuery) Field() string{ + return q.FieldVal } func (q *MatchQuery) SetFuzziness(f int) { @@ -116,8 +116,8 @@ func (q *MatchQuery) SetOperator(operator MatchQueryOperator) { func (q *MatchQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { - field := q.Field - if q.Field == "" { + field := q.FieldVal + if q.FieldVal == "" { field = m.DefaultSearchField() } @@ -143,14 +143,14 @@ func (q *MatchQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, expla query.SetFuzziness(q.Fuzziness) query.SetPrefix(q.Prefix) query.SetField(field) - query.SetBoost(q.Boost.Value()) + query.SetBoost(q.BoostVal.Value()) tqs[i] = query } } else { for i, token := range tokens { tq := NewTermQuery(string(token.Term)) tq.SetField(field) - tq.SetBoost(q.Boost.Value()) + tq.SetBoost(q.BoostVal.Value()) tqs[i] = tq } } @@ -159,12 +159,12 @@ func (q *MatchQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, expla case MatchQueryOperatorOr: shouldQuery := NewDisjunctionQuery(tqs) shouldQuery.SetMin(1) - shouldQuery.SetBoost(q.Boost.Value()) + shouldQuery.SetBoost(q.BoostVal.Value()) return shouldQuery.Searcher(i, m, explain) case MatchQueryOperatorAnd: mustQuery := NewConjunctionQuery(tqs) - mustQuery.SetBoost(q.Boost.Value()) + mustQuery.SetBoost(q.BoostVal.Value()) return mustQuery.Searcher(i, m, explain) default: diff --git a/search/query/match_phrase.go b/search/query/match_phrase.go index fa0721f9..a148808f 100644 --- a/search/query/match_phrase.go +++ b/search/query/match_phrase.go @@ -25,9 +25,9 @@ import ( type MatchPhraseQuery struct { MatchPhrase string `json:"match_phrase"` - Field string `json:"field,omitempty"` + FieldVal string `json:"field,omitempty"` Analyzer string `json:"analyzer,omitempty"` - Boost *Boost `json:"boost,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` } // NewMatchPhraseQuery creates a new Query object @@ -46,24 +46,24 @@ func NewMatchPhraseQuery(matchPhrase string) *MatchPhraseQuery { func (q *MatchPhraseQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *MatchPhraseQuery) Boost() float64{ + return q.BoostVal.Value() } func (q *MatchPhraseQuery) SetField(f string) { - q.Field = f + q.FieldVal = f } -func (q *MatchPhraseQuery) GetField() string{ - return q.Field -} - -func (q *MatchPhraseQuery) GetBoost() float64{ - return q.Boost.Value() +func (q *MatchPhraseQuery) Field() string{ + return q.FieldVal } func (q *MatchPhraseQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { - field := q.Field - if q.Field == "" { + field := q.FieldVal + if q.FieldVal == "" { field = m.DefaultSearchField() } @@ -82,7 +82,7 @@ func (q *MatchPhraseQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, if len(tokens) > 0 { phrase := tokenStreamToPhrase(tokens) phraseQuery := NewPhraseQuery(phrase, field) - phraseQuery.SetBoost(q.Boost.Value()) + phraseQuery.SetBoost(q.BoostVal.Value()) return phraseQuery.Searcher(i, m, explain) } noneQuery := NewMatchNoneQuery() diff --git a/search/query/numeric_range.go b/search/query/numeric_range.go index 41d1157d..93f7fd6b 100644 --- a/search/query/numeric_range.go +++ b/search/query/numeric_range.go @@ -28,8 +28,8 @@ type NumericRangeQuery struct { Max *float64 `json:"max,omitempty"` InclusiveMin *bool `json:"inclusive_min,omitempty"` InclusiveMax *bool `json:"inclusive_max,omitempty"` - Field string `json:"field,omitempty"` - Boost *Boost `json:"boost,omitempty"` + FieldVal string `json:"field,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` } // NewNumericRangeQuery creates a new Query for ranges @@ -56,27 +56,27 @@ func NewNumericRangeInclusiveQuery(min, max *float64, minInclusive, maxInclusive func (q *NumericRangeQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *NumericRangeQuery) Boost() float64{ + return q.BoostVal.Value() } func (q *NumericRangeQuery) SetField(f string) { - q.Field = f + q.FieldVal = f } -func (q *NumericRangeQuery) GetField() string{ - return q.Field -} - -func (q *NumericRangeQuery) GetBoost() float64{ - return q.Boost.Value() +func (q *NumericRangeQuery) Field() string{ + return q.FieldVal } func (q *NumericRangeQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { - field := q.Field - if q.Field == "" { + field := q.FieldVal + if q.FieldVal == "" { field = m.DefaultSearchField() } - return searcher.NewNumericRangeSearcher(i, q.Min, q.Max, q.InclusiveMin, q.InclusiveMax, field, q.Boost.Value(), explain) + return searcher.NewNumericRangeSearcher(i, q.Min, q.Max, q.InclusiveMin, q.InclusiveMax, field, q.BoostVal.Value(), explain) } func (q *NumericRangeQuery) Validate() error { diff --git a/search/query/phrase.go b/search/query/phrase.go index 96cbe413..2d382bbd 100644 --- a/search/query/phrase.go +++ b/search/query/phrase.go @@ -87,7 +87,7 @@ func (q *PhraseQuery) UnmarshalJSON(data []byte) error { q.Boost = tmp.Boost q.termQueries = make([]Query, len(q.Terms)) for i, term := range q.Terms { - q.termQueries[i] = &TermQuery{Term: term, Field: q.Field, Boost: q.Boost} + q.termQueries[i] = &TermQuery{Term: term, FieldVal: q.Field, BoostVal: q.Boost} } return nil } diff --git a/search/query/prefix.go b/search/query/prefix.go index f71e1106..d8c2bb2f 100644 --- a/search/query/prefix.go +++ b/search/query/prefix.go @@ -22,9 +22,9 @@ import ( ) type PrefixQuery struct { - Prefix string `json:"prefix"` - Field string `json:"field,omitempty"` - Boost *Boost `json:"boost,omitempty"` + Prefix string `json:"prefix"` + FieldVal string `json:"field,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` } // NewPrefixQuery creates a new Query which finds @@ -38,25 +38,25 @@ func NewPrefixQuery(prefix string) *PrefixQuery { func (q *PrefixQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *PrefixQuery) Boost() float64{ + return q.BoostVal.Value() } func (q *PrefixQuery) SetField(f string) { - q.Field = f + q.FieldVal = f } -func (q *PrefixQuery) GetField() string{ - return q.Field -} - -func (q *PrefixQuery) GetBoost() float64{ - return q.Boost.Value() +func (q *PrefixQuery) Field() string{ + return q.FieldVal } func (q *PrefixQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { - field := q.Field - if q.Field == "" { + field := q.FieldVal + if q.FieldVal == "" { field = m.DefaultSearchField() } - return searcher.NewTermPrefixSearcher(i, q.Prefix, field, q.Boost.Value(), explain) + return searcher.NewTermPrefixSearcher(i, q.Prefix, field, q.BoostVal.Value(), explain) } diff --git a/search/query/query.go b/search/query/query.go index d0867b8c..711bf931 100644 --- a/search/query/query.go +++ b/search/query/query.go @@ -44,7 +44,7 @@ type Query interface { type BoostableQuery interface { Query SetBoost(b float64) - GetBoost() float64 + Boost() float64 } // A FieldableQuery represents a Query which can be restricted @@ -52,7 +52,7 @@ type BoostableQuery interface { type FieldableQuery interface { Query SetField(f string) - GetField() string + Field() string } // A ValidatableQuery represents a Query which can be validated diff --git a/search/query/regexp.go b/search/query/regexp.go index f246c5c1..21d29b71 100644 --- a/search/query/regexp.go +++ b/search/query/regexp.go @@ -26,8 +26,8 @@ import ( type RegexpQuery struct { Regexp string `json:"regexp"` - Field string `json:"field,omitempty"` - Boost *Boost `json:"boost,omitempty"` + FieldVal string `json:"field,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` compiled *regexp.Regexp } @@ -42,24 +42,24 @@ func NewRegexpQuery(regexp string) *RegexpQuery { func (q *RegexpQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *RegexpQuery) Boost() float64{ + return q.BoostVal.Value() } func (q *RegexpQuery) SetField(f string) { - q.Field = f + q.FieldVal = f } -func (q *RegexpQuery) GetField() string{ - return q.Field -} - -func (q *RegexpQuery) GetBoost() float64{ - return q.Boost.Value() +func (q *RegexpQuery) Field() string{ + return q.FieldVal } func (q *RegexpQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { - field := q.Field - if q.Field == "" { + field := q.FieldVal + if q.FieldVal == "" { field = m.DefaultSearchField() } err := q.compile() @@ -67,7 +67,7 @@ func (q *RegexpQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, expl return nil, err } - return searcher.NewRegexpSearcher(i, q.compiled, field, q.Boost.Value(), explain) + return searcher.NewRegexpSearcher(i, q.compiled, field, q.BoostVal.Value(), explain) } func (q *RegexpQuery) Validate() error { diff --git a/search/query/term.go b/search/query/term.go index 446ecb67..0e939ad3 100644 --- a/search/query/term.go +++ b/search/query/term.go @@ -22,9 +22,9 @@ import ( ) type TermQuery struct { - Term string `json:"term"` - Field string `json:"field,omitempty"` - Boost *Boost `json:"boost,omitempty"` + Term string `json:"term"` + FieldVal string `json:"field,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` } // NewTermQuery creates a new Query for finding an @@ -37,25 +37,25 @@ func NewTermQuery(term string) *TermQuery { func (q *TermQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *TermQuery) Boost() float64{ + return q.BoostVal.Value() } func (q *TermQuery) SetField(f string) { - q.Field = f + q.FieldVal = f } -func (q *TermQuery) GetField() string{ - return q.Field -} - -func (q *TermQuery) GetBoost() float64{ - return q.Boost.Value() +func (q *TermQuery) Field() string{ + return q.FieldVal } func (q *TermQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { - field := q.Field - if q.Field == "" { + field := q.FieldVal + if q.FieldVal == "" { field = m.DefaultSearchField() } - return searcher.NewTermSearcher(i, q.Term, field, q.Boost.Value(), explain) + return searcher.NewTermSearcher(i, q.Term, field, q.BoostVal.Value(), explain) } diff --git a/search/query/wildcard.go b/search/query/wildcard.go index 7d248758..e2adc24b 100644 --- a/search/query/wildcard.go +++ b/search/query/wildcard.go @@ -45,8 +45,8 @@ var wildcardRegexpReplacer = strings.NewReplacer( type WildcardQuery struct { Wildcard string `json:"wildcard"` - Field string `json:"field,omitempty"` - Boost *Boost `json:"boost,omitempty"` + FieldVal string `json:"field,omitempty"` + BoostVal *Boost `json:"boost,omitempty"` compiled *regexp.Regexp } @@ -63,24 +63,24 @@ func NewWildcardQuery(wildcard string) *WildcardQuery { func (q *WildcardQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost } func (q *WildcardQuery) SetField(f string) { - q.Field = f + q.FieldVal = f } -func (q *WildcardQuery) GetField() string{ - return q.Field +func (q *WildcardQuery) Field() string{ + return q.FieldVal } -func (q *WildcardQuery) GetBoost() float64{ - return q.Boost.Value() +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.Field - if q.Field == "" { + field := q.FieldVal + if q.FieldVal == "" { field = m.DefaultSearchField() } if q.compiled == nil { @@ -91,7 +91,7 @@ func (q *WildcardQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, ex } } - return searcher.NewRegexpSearcher(i, q.compiled, field, q.Boost.Value(), explain) + return searcher.NewRegexpSearcher(i, q.compiled, field, q.BoostVal.Value(), explain) } func (q *WildcardQuery) Validate() error {