-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathraw.go
55 lines (46 loc) · 1.5 KB
/
raw.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
package solr
import "encoding/json"
// The *Raw structs are used to unmarshall the JSON from Solr
// via Go's built-in functions. They are not exposed outside
// the solr package.
type headerRaw struct {
Status int `json:"status"`
QTime int `json:"QTime"`
// Use interface{} because some params are strings and
// others (e.g. fq) are arrays of strings.
Params map[string]interface{} `json:"params"`
}
type dataRaw struct {
NumFound int `json:"numFound"`
Start int `json:"start"`
Documents []documentRaw `json:"docs"`
}
// Just as it comes from Solr
type documentRaw map[string]interface{}
// fieldname: [value1, value2, ...]
type highlightRow map[string][]string
type errorRaw struct {
Trace string `json:"trace"`
Code int `json:"code"`
}
type responseRaw struct {
Header headerRaw `json:"responseHeader"`
Data dataRaw `json:"response"`
Error errorRaw `json:"error"`
FacetCounts facetCountsRaw `json:"facet_counts"`
Highlighting map[string]highlightRow `json:"highlighting"`
Raw string `json:"raw"`
}
func NewResponseRaw(rawBytes []byte) (responseRaw, error) {
var response responseRaw
err := json.Unmarshal([]byte(rawBytes), &response)
if err != nil {
return response, err
}
response.Raw = string(rawBytes)
return response, nil
}
type facetCountsRaw struct {
Queries interface{} `json:"facet_queries"`
Fields map[string][]interface{} `json:"facet_fields"`
}