-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathsearchquery_facet.go
110 lines (94 loc) · 2.68 KB
/
searchquery_facet.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
package gocb
import (
"encoding/json"
)
// FtsFacet represents a facet for a search query.
type FtsFacet interface {
}
type termFacetData struct {
Field string `json:"field,omitempty"`
Size int `json:"size,omitempty"`
}
// TermFacet is an FTS term facet.
type TermFacet struct {
data termFacetData
}
// MarshalJSON marshal's this facet to JSON for the FTS REST API.
func (f TermFacet) MarshalJSON() ([]byte, error) {
return json.Marshal(f.data)
}
// NewTermFacet creates a new TermFacet
func NewTermFacet(field string, size int) *TermFacet {
mq := &TermFacet{}
mq.data.Field = field
mq.data.Size = size
return mq
}
type numericFacetRange struct {
Name string `json:"name,omitempty"`
Start float64 `json:"start,omitempty"`
End float64 `json:"end,omitempty"`
}
type numericFacetData struct {
Field string `json:"field,omitempty"`
Size int `json:"size,omitempty"`
NumericRanges []numericFacetRange `json:"numeric_ranges,omitempty"`
}
// NumericFacet is an FTS numeric range facet.
type NumericFacet struct {
data numericFacetData
}
// MarshalJSON marshal's this facet to JSON for the FTS REST API.
func (f NumericFacet) MarshalJSON() ([]byte, error) {
return json.Marshal(f.data)
}
// AddRange adds a new range to this numeric range facet.
func (f *NumericFacet) AddRange(name string, start, end float64) *NumericFacet {
f.data.NumericRanges = append(f.data.NumericRanges, numericFacetRange{
Name: name,
Start: start,
End: end,
})
return f
}
// NewNumericFacet creates a new numeric range facet.
func NewNumericFacet(field string, size int) *NumericFacet {
mq := &NumericFacet{}
mq.data.Field = field
mq.data.Size = size
return mq
}
type dateFacetRange struct {
Name string `json:"name,omitempty"`
Start string `json:"start,omitempty"`
End string `json:"end,omitempty"`
}
type dateFacetData struct {
Field string `json:"field,omitempty"`
Size int `json:"size,omitempty"`
DateRanges []dateFacetRange `json:"date_ranges,omitempty"`
}
// DateFacet is an FTS date range facet.
type DateFacet struct {
data dateFacetData
}
// MarshalJSON marshal's this facet to JSON for the FTS REST API.
func (f DateFacet) MarshalJSON() ([]byte, error) {
return json.Marshal(f.data)
}
// AddRange adds a new range to this date range facet.
func (f *DateFacet) AddRange(name string, start, end string) *DateFacet {
f.data.DateRanges = append(f.data.DateRanges, dateFacetRange{
Name: name,
Start: start,
End: end,
})
return f
}
// NewDateFacet creates a new date range facet.
func NewDateFacet(field string, size int) *DateFacet {
mq := &DateFacet{}
mq.data.Field = field
mq.data.Size = size
return mq
}