-
Notifications
You must be signed in to change notification settings - Fork 10
/
collection_params.go
66 lines (53 loc) · 1.36 KB
/
collection_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
package solr
import (
"net/url"
"strconv"
)
// CollectionParams is the collection API param builder
type CollectionParams struct {
name string
numShards int
replicationFactor int
requestID string
}
// NewCollectionParams returns a new CollectionParams
func NewCollectionParams() *CollectionParams {
return &CollectionParams{}
}
// Name sets the collection name
func (c *CollectionParams) Name(name string) *CollectionParams {
c.name = name
return c
}
// NumShards sets the number of shards
func (c *CollectionParams) NumShards(ns int) *CollectionParams {
c.numShards = ns
return c
}
// ReplicationFactor sets the replication factor
func (c *CollectionParams) ReplicationFactor(rf int) *CollectionParams {
c.replicationFactor = rf
return c
}
// Async enable async request with a request ID to track this action
func (c *CollectionParams) Async(requestID string) *CollectionParams {
c.requestID = requestID
return c
}
// BuildParams builds the parameters
func (c *CollectionParams) BuildParams() string {
vals := &url.Values{}
if c.name != "" {
vals.Add("name", c.name)
}
if c.numShards > 0 {
vals.Add("numShards", strconv.Itoa(c.numShards))
}
if c.replicationFactor > 0 {
vals.Add("replicationFactor", strconv.Itoa(c.replicationFactor))
}
if c.requestID != "" {
vals.Add("async", c.requestID)
}
return vals.Encode()
}