-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.go
66 lines (54 loc) · 1.74 KB
/
filter.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 es_filter_query
import (
"encoding/xml"
"gopkg.in/olivere/elastic.v5"
)
type FilterGroup struct {
XMLName xml.Name `json:"-" yaml:"-" xml:"Filter"`
Label string `json:"label" yaml:"label" xml:",attr"`
Class string `json:"class" yaml:"class" xml:",attr"`
Filters []Filter `json:"filters" yaml:"filters" xml:">Filter"`
}
type Filter struct {
XMLName xml.Name `json:"-" yaml:"-" xml:"Filter"`
ID string `json:"id" yaml:"id" xml:",attr"`
Label string `json:"label" yaml:"label" xml:",attr"`
Selection string `json:"selection" yaml:"selection" xml:",attr"`
Logic string `json:"logic" yaml:"logic" xml:",attr"`
Field string `json:"field" yaml:"field" xml:",attr"`
Static bool `json:"static" yaml:"static" xml:",attr"`
Facets []Facet `json:"facets" yaml:"facets" xml:">Facet"`
Format string `json:"format" yaml:"format" xml:"format"`
}
type Facet struct {
XMLName xml.Name `json:"-" yaml:"-" xml:"Facet"`
ID string `json:"id" yaml:"id" xml:",attr"`
Label string `json:"label" yaml:"label" xml:",attr"`
Query string `json:"query" yaml:"query" xml:",chardata"`
Count int64 `json:"count" yaml:"count" xml:",attr"`
}
type FilterMap map[string]Filter
type FilterAggs map[string]elastic.Aggregation
func (f *FilterGroup)GetFilter(fieldName string) (filter Filter) {
for _, filter = range f.Filters {
if filter.Field == fieldName {
return
}
}
return Filter{}
}
func (f *FilterGroup)ReplaceFilter(filter Filter) {
for idx, fil := range f.Filters {
if fil.Field == filter.Field {
f.Filters[idx] = filter
}
}
}
func (f *Filter)GetFacet(label string) (facet Facet) {
for _, facet = range f.Facets {
if facet.Label == label {
return
}
}
return Facet{}
}