github.com/ravendb/ravendb-go-client@v0.0.0-20240229102137-4474ee7aa0fa/suggestion_builder.go (about) 1 package ravendb 2 3 // SuggestionsBuilder helps to build argument to SuggestUsing 4 type SuggestionBuilder struct { 5 term *SuggestionWithTerm 6 terms *SuggestionWithTerms 7 } 8 9 func NewSuggestionBuilder() *SuggestionBuilder { 10 return &SuggestionBuilder{} 11 } 12 13 func (b *SuggestionBuilder) ByField(fieldName string, term string, terms ...string) *SuggestionBuilder { 14 panicIf(fieldName == "", "fieldName cannot be empty") 15 panicIf(term == "", "term cannot be empty") 16 if len(terms) > 0 { 17 b.terms = NewSuggestionWithTerms(fieldName) 18 b.terms.Terms = append([]string{term}, terms...) 19 } else { 20 b.term = NewSuggestionWithTerm(fieldName) 21 b.term.Term = term 22 } 23 return b 24 } 25 26 func (b *SuggestionBuilder) GetSuggestion() SuggestionBase { 27 if b.term != nil { 28 return b.term 29 } 30 31 return b.terms 32 } 33 34 func (b *SuggestionBuilder) WithOptions(options *SuggestionOptions) *SuggestionBuilder { 35 b.GetSuggestion().SetOptions(options) 36 37 return b 38 }