@@ -60,22 +60,6 @@ extension esb {
60
60
}
61
61
}
62
62
63
- /// Adds `query` block to the query syntax.
64
- public struct Query < Component: DictComponent > : DictComponent {
65
- var component : Component
66
- public init ( @QueryDictBuilder component: ( ) -> Component ) {
67
- self . component = component ( )
68
- }
69
- public func makeDict( ) -> QueryDict {
70
- let dict = self . component. makeDict ( )
71
- if dict. isEmpty {
72
- return [ : ]
73
- } else {
74
- return [ " query " : . dict( self . component. makeDict ( ) ) ]
75
- }
76
- }
77
- }
78
-
79
63
/// Adds a `key` with any type of value to the query syntax.
80
64
public struct Key : DictComponent {
81
65
var key : String
@@ -108,6 +92,73 @@ extension esb {
108
92
}
109
93
}
110
94
95
+ /// Adds a block to the syntax.
96
+ public struct Dict < Component: DictComponent > : DictComponent {
97
+ var key : String
98
+ var component : Component
99
+ public init ( _ key: String , @QueryDictBuilder component: ( ) -> Component ) {
100
+ self . key = key
101
+ self . component = component ( )
102
+ }
103
+ public func makeDict( ) -> QueryDict {
104
+ let dict = self . component. makeDict ( )
105
+ if dict. isEmpty {
106
+ return [ : ]
107
+ } else {
108
+ return [ key : . dict( self . component. makeDict ( ) ) ]
109
+ }
110
+ }
111
+ }
112
+
113
+ /// Adds a `query` block to the syntax.
114
+ public struct Query < Component: DictComponent > : DictComponent {
115
+ var component : Component
116
+ public init ( @QueryDictBuilder component: ( ) -> Component ) {
117
+ self . component = component ( )
118
+ }
119
+ public func makeDict( ) -> QueryDict {
120
+ let dict = self . component. makeDict ( )
121
+ if dict. isEmpty {
122
+ return [ : ]
123
+ } else {
124
+ return [ " query " : . dict( self . component. makeDict ( ) ) ]
125
+ }
126
+ }
127
+ }
128
+
129
+ /// Adds an `aggs` block to the syntax.
130
+ public struct Aggs < Component: DictComponent > : DictComponent {
131
+ var component : Component
132
+ public init ( @QueryDictBuilder component: ( ) -> Component ) {
133
+ self . component = component ( )
134
+ }
135
+ public func makeDict( ) -> QueryDict {
136
+ let dict = self . component. makeDict ( )
137
+ if dict. isEmpty {
138
+ return [ : ]
139
+ } else {
140
+ return [ " aggs " : . dict( self . component. makeDict ( ) ) ]
141
+ }
142
+ }
143
+ }
144
+
145
+ /// Defines and named aggregate within `Aggs`
146
+ public struct Agg : DictComponent {
147
+ var name : String
148
+ var term : QueryDict
149
+ public init ( _ name: String , field: String ) {
150
+ self . name = name
151
+ self . term = [ " field " : . string( field) ]
152
+ }
153
+ public init ( _ name: String , term: QueryDict ) {
154
+ self . name = name
155
+ self . term = term
156
+ }
157
+ public func makeDict( ) -> QueryDict {
158
+ return [ self . name : [ " terms " : . dict( self . term) ] ]
159
+ }
160
+ }
161
+
111
162
/// Adds `minimum_should_match` to the query syntax.
112
163
public struct MinimumShouldMatch : DictComponent {
113
164
var count : Int
0 commit comments