-
Notifications
You must be signed in to change notification settings - Fork 0
/
facets.go
94 lines (82 loc) · 1.93 KB
/
facets.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
package humus
import "strings"
//TODO: Allow proper auto-generation of facets. Is it needed though, is @facets poor performance?
type facet struct {
active bool
m modifierList
}
func (f *facetCreator) Paginate(t PaginationType, value int) bool {
return false
}
func (f *facetCreator) Variable(name string, value string, isAlias bool) bool {
f.f.m = append(f.f.m, variable{
name: name,
value: value,
alias: isAlias,
})
return true
}
/*
Applies a filter on the current facet.
*/
func (f *facetCreator) Filter(t FunctionType, variables ...interface{}) bool {
var filter Filter
//Only allow one filter as a modifier for now since there is no way to allow connecting filters.
for _, v := range f.f.m {
if v.priority() == modifierFilter {
return false
}
}
filter.typ = t
filter.variables = make([]graphVariable, len(variables))
for k, v := range variables {
val, typ := processInterface(v)
filter.variables[k] = graphVariable{
Value: val,
Type: typ,
}
}
filter.mapVariables(f.q)
filter.ignoreHeader = true
f.f.m = append(f.f.m, &filter)
return true
}
func (f *facetCreator) Sort(t OrderType, p Predicate) bool {
f.f.m = append(f.f.m, Ordering{
Type: t,
Predicate: p,
})
return true
}
func (f *facetCreator) Aggregate(t AggregateType, v string, alias string) bool {
f.m = append(f.m, aggregateValues{
Type: t,
Alias: alias,
Variable: v,
})
return true
}
func (f *facetCreator) Count(p Predicate, alias string) bool {
return false
}
func (f facet) canApply(mt modifierSource) bool {
return mt == modifierField
}
func (f facet) apply(root *GeneratedQuery, meta FieldMeta, mt modifierSource, sb *strings.Builder) error {
if len(f.m) > 0 {
f.m.sort()
err := f.m.runFacet(root, meta, sb)
if err != nil {
return err
}
} else {
sb.WriteString("@facets")
}
return nil
}
func (f facet) priority() modifierType {
return modifierFacet
}
func (f facet) parenthesis() bool {
return false
}