Skip to content

Commit 552fab6

Browse files
committed
add bool value
1 parent b788c41 commit 552fab6

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Sources/ElasticsearchQueryBuilder/Encoding.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ extension QueryValue: Encodable {
66
switch self {
77
case let .array(value):
88
try container.encode(value)
9+
case let .bool(value):
10+
try container.encode(value)
911
case let .date(value, format: format):
1012
switch format {
1113
case .secondsSince1970:

Sources/ElasticsearchQueryBuilder/QueryValue.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public typealias QueryDict = [ String : QueryValue ]
44

55
public enum QueryValue: Equatable {
66
case array([QueryValue])
7+
case bool(Bool)
78
case date(Date, format: QueryDateFormat)
89
case dict(QueryDict)
910
case float(Float)
@@ -45,6 +46,12 @@ extension QueryValue: ExpressibleByArrayLiteral {
4546
}
4647
}
4748

49+
extension QueryValue: ExpressibleByBooleanLiteral {
50+
public init(booleanLiteral value: Bool) {
51+
self = .bool(value)
52+
}
53+
}
54+
4855
extension QueryValue: ExpressibleByDictionaryLiteral {
4956
public init(dictionaryLiteral elements: (String, QueryValue)...) {
5057
var dict = QueryDict()

Tests/ElasticsearchQueryBuilderTests/ComponentTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ final class KNearestNeighborTests: XCTestCase {
191191
@ElasticsearchQueryBuilder func build() -> some esb.QueryDSL {
192192
esb.KNearestNeighbor("vector_field", [1,2,3]) {
193193
[
194-
"k": 5
194+
"k": 5,
195+
"index": true
195196
]
196197
} filter: {
197198
esb.Key("match_bool_prefix") {
@@ -206,6 +207,7 @@ final class KNearestNeighborTests: XCTestCase {
206207
"field": "vector_field",
207208
"query_vector": [1.0, 2.0, 3.0],
208209
"k": 5,
210+
"index": true,
209211
"filter": [
210212
[
211213
"match_bool_prefix": [

0 commit comments

Comments
 (0)