diff --git a/search/query/bool_field.go b/search/query/bool_field.go index 43c71329..402724ce 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,21 +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) 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/boolean.go b/search/query/boolean.go index ea7f5dec..2fe75ff9 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,11 @@ 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{ + return q.BoostVal.Value() } func (q *BooleanQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { @@ -199,7 +203,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..e819d697 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,11 @@ 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{ + return q.BoostVal.Value() } func (q *ConjunctionQuery) AddQuery(aq ...Query) { @@ -93,6 +97,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 be69a70a..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,11 +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) Field() string{ + return q.FieldVal } func (q *DateRangeQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { @@ -123,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/disjunction.go b/search/query/disjunction.go index b4b8575e..08f47c41 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,14 @@ 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{ + return q.BoostVal.Value() +} + + func (q *DisjunctionQuery) AddQuery(aq ...Query) { for _, aaq := range aq { q.Disjuncts = append(q.Disjuncts, aaq) @@ -103,7 +108,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..c633d947 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,13 @@ 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{ + return q.BoostVal.Value() } 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 fd868fb1..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,11 +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) Field() string{ + return q.FieldVal } func (q *FuzzyQuery) SetFuzziness(f int) { @@ -61,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 d8d905b1..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,11 +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) Field() string{ + return q.FieldVal } func (q *MatchQuery) SetFuzziness(f int) { @@ -108,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() } @@ -135,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 } } @@ -151,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_all.go b/search/query/match_all.go index d33e2bb2..9eb7eb95 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,22 @@ func NewMatchAllQuery() *MatchAllQuery { func (q *MatchAllQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost } +func (q *MatchAllQuery) Boost() float64{ + return q.BoostVal.Value() +} + + + 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..5264c5a6 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,11 @@ func NewMatchNoneQuery() *MatchNoneQuery { func (q *MatchNoneQuery) SetBoost(b float64) { boost := Boost(b) - q.Boost = &boost + q.BoostVal = &boost +} + +func (q *MatchNoneQuery) Boost() float64{ + return q.BoostVal.Value() } func (q *MatchNoneQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { @@ -44,7 +48,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 6c08b3ae..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,16 +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) 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() } @@ -74,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 ea35ef4d..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,19 +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) 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..0cd608b8 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,11 @@ 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{ + return q.BoostVal.Value() } func (q *PhraseQuery) Searcher(i index.IndexReader, m mapping.IndexMapping, explain bool) (search.Searcher, error) { @@ -84,10 +88,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, Field: q.Field, Boost: 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 0e5f03eb..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,17 +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) 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 9e7a2e97..bb65a075 100644 --- a/search/query/query.go +++ b/search/query/query.go @@ -44,6 +44,7 @@ type Query interface { type BoostableQuery interface { Query SetBoost(b float64) + Boost() float64 } // A FieldableQuery represents a Query which can be restricted @@ -51,6 +52,7 @@ type BoostableQuery interface { type FieldableQuery interface { Query SetField(f string) + Field() string } // A ValidatableQuery represents a Query which can be validated diff --git a/search/query/query_string.go b/search/query/query_string.go index 1e2785d7..d8f421f4 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,11 @@ 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{ + return q.BoostVal.Value() } 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 9dd8c842..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,16 +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) 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() @@ -59,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 c5bc2da1..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,17 +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) 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 5f5c864c..51a8cdef 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,16 +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) Boost() float64{ + return q.BoostVal.Value() } func (q *WildcardQuery) SetField(f string) { - q.Field = f + q.FieldVal = f +} + +func (q *WildcardQuery) Field() string{ + return q.FieldVal } 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 { @@ -83,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 {