forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuggestion_builder.go
38 lines (31 loc) · 925 Bytes
/
suggestion_builder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package ravendb
// SuggestionsBuilder helps to build argument to SuggestUsing
type SuggestionBuilder struct {
term *SuggestionWithTerm
terms *SuggestionWithTerms
}
func NewSuggestionBuilder() *SuggestionBuilder {
return &SuggestionBuilder{}
}
func (b *SuggestionBuilder) ByField(fieldName string, term string, terms ...string) *SuggestionBuilder {
panicIf(fieldName == "", "fieldName cannot be empty")
panicIf(term == "", "term cannot be empty")
if len(terms) > 0 {
b.terms = NewSuggestionWithTerms(fieldName)
b.terms.Terms = append([]string{term}, terms...)
} else {
b.term = NewSuggestionWithTerm(fieldName)
b.term.Term = term
}
return b
}
func (b *SuggestionBuilder) GetSuggestion() SuggestionBase {
if b.term != nil {
return b.term
}
return b.terms
}
func (b *SuggestionBuilder) WithOptions(options *SuggestionOptions) *SuggestionBuilder {
b.GetSuggestion().SetOptions(options)
return b
}