-
Notifications
You must be signed in to change notification settings - Fork 10
/
suggester_params.go
131 lines (101 loc) · 2.61 KB
/
suggester_params.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package solr
import (
"net/url"
"strconv"
)
// SuggestParams is the suggester API param builder
type SuggestParams struct {
endpoint string
// dicts is the name of the dictionary
// component configured in the search component
dicts []string
// query is the query to use for suggestion lookups
query,
// cfq is a context filter query used to filter suggestsion
// based on the context field, if supported by the suggester
cfq string
// count is the number of suggestions to return
count int
// build If true, it will build the suggester index
build,
// Reload If true, it will reload the suggester index.
reload,
// BuildAll If true, it will build all suggester indexes.
buildAll,
// ReloadAll If true, it will reload all suggester indexes.
reloadAll bool
}
// NewSuggesterParams returns a new SuggesterParams
func NewSuggesterParams(endpoint string) *SuggestParams {
return &SuggestParams{endpoint: endpoint}
}
// BuildParams builds the suggester params
func (sp *SuggestParams) BuildParams() string {
params := url.Values{}
params.Add("suggest", "true")
for _, dict := range sp.dicts {
params.Add("suggest.dictionary", dict)
}
if sp.query != "" {
params.Add("suggest.q", sp.query)
}
if sp.count > 0 {
params.Add("suggest.count", strconv.Itoa(sp.count))
}
if sp.cfq != "" {
params.Add("suggest.cfg", sp.cfq)
}
if sp.build {
params.Add("suggest.build", "true")
}
if sp.reload {
params.Add("suggest.reload", "true")
}
if sp.buildAll {
params.Add("suggest.buildAll", "true")
}
if sp.reloadAll {
params.Add("suggest.reloadAll", "true")
}
return params.Encode()
}
// Dictionaries sets the dictionaries param
func (sp *SuggestParams) Dictionaries(dicts ...string) *SuggestParams {
sp.dicts = dicts
return sp
}
// Query sets the query param
func (sp *SuggestParams) Query(query string) *SuggestParams {
sp.query = query
return sp
}
// Cfq sets the context filter query param
func (sp *SuggestParams) Cfq(cfq string) *SuggestParams {
sp.cfq = cfq
return sp
}
// Count sets the count param
func (sp *SuggestParams) Count(count int) *SuggestParams {
sp.count = count
return sp
}
// Build sets the build param to true
func (sp *SuggestParams) Build() *SuggestParams {
sp.build = true
return sp
}
// Reload sets the reload param to true
func (sp *SuggestParams) Reload() *SuggestParams {
sp.reload = true
return sp
}
// BuildAll sets the build-all param to true
func (sp *SuggestParams) BuildAll() *SuggestParams {
sp.buildAll = true
return sp
}
// ReloadAll sets the reload-all param to true
func (sp *SuggestParams) ReloadAll() *SuggestParams {
sp.reloadAll = true
return sp
}