Skip to content

Commit b13998c

Browse files
feat: hit _geoloc field improvement (#704)
– Hit parsing don't fail if the format of Point for _geoloc is wrong – Detailed errors in case of Point parsing failure – Add possibility to represent _geoloc as a list of points
1 parent 65d8343 commit b13998c

File tree

25 files changed

+198
-124
lines changed

25 files changed

+198
-124
lines changed

Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let macOSVersion: SupportedPlatform.MacOSVersion = .v10_10
1111

1212
#if os(Linux)
1313
let extraPackageDependencies: [Package.Dependency] = [
14-
.package(url: "https://github.com/apple/swift-crypto.git", from: "1.1.2"),
14+
.package(url: "https://github.com/apple/swift-crypto.git", from: "1.1.2")
1515
]
1616
#else
1717
let extraPackageDependencies: [Package.Dependency] = []
@@ -39,19 +39,19 @@ let package = Package(
3939
targets: ["AlgoliaSearchClient"])
4040
],
4141
dependencies: [
42-
.package(url:"https://github.com/apple/swift-log.git", from: "1.4.0"),
42+
.package(url:"https://github.com/apple/swift-log.git", from: "1.4.0")
4343
] + extraPackageDependencies,
4444
targets: [
4545
.target(
4646
name: "AlgoliaSearchClient",
4747
dependencies: [
48-
.product(name: "Logging", package: "swift-log"),
48+
.product(name: "Logging", package: "swift-log")
4949
] + extraTargetDependencies),
5050
.testTarget(
5151
name: "AlgoliaSearchClientTests",
5252
dependencies: [
5353
.target(name: "AlgoliaSearchClient"),
54-
.product(name: "Logging", package: "swift-log"),
54+
.product(name: "Logging", package: "swift-log")
5555
] + extraTargetDependencies)
5656
]
5757
)

Sources/AlgoliaSearchClient/Client/Search/SearchClient+MultiCluster.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import Foundation
99

1010
public extension SearchClient {
11-
11+
1212
// MARK: - List clusters
13-
13+
1414
/**
1515
List the Cluster available in a multi-clusters setup for a single ApplicationID.
1616

@@ -23,7 +23,7 @@ public extension SearchClient {
2323
let command = Command.MultiCluster.ListClusters(requestOptions: requestOptions)
2424
return execute(command, completion: completion)
2525
}
26-
26+
2727
/**
2828
List the Cluster available in a multi-clusters setup for a single ApplicationID.
2929

@@ -34,9 +34,9 @@ public extension SearchClient {
3434
let command = Command.MultiCluster.ListClusters(requestOptions: requestOptions)
3535
return try execute(command)
3636
}
37-
37+
3838
// MARK: - List User IDs
39-
39+
4040
/**
4141
List the UserID assigned to a multi-clusters ApplicationID.
4242

@@ -55,7 +55,7 @@ public extension SearchClient {
5555
let command = Command.MultiCluster.User.GetList(page: page, hitsPerPage: hitsPerPage, requestOptions: requestOptions)
5656
return execute(command, completion: completion)
5757
}
58-
58+
5959
/**
6060
List the UserID assigned to a multi-clusters ApplicationID.
6161

@@ -72,7 +72,7 @@ public extension SearchClient {
7272
let command = Command.MultiCluster.User.GetList(page: page, hitsPerPage: hitsPerPage, requestOptions: requestOptions)
7373
return try execute(command)
7474
}
75-
75+
7676
// MARK: - Assign UserID
7777
/**
7878
Assign or Move a UserID to a cluster.
@@ -93,7 +93,7 @@ public extension SearchClient {
9393
let command = Command.MultiCluster.User.Assign(userID: userID, clusterName: clusterName, requestOptions: requestOptions)
9494
return execute(command, completion: completion)
9595
}
96-
96+
9797
/**
9898
Assign or Move a UserID to a cluster.
9999

@@ -111,9 +111,9 @@ public extension SearchClient {
111111
let command = Command.MultiCluster.User.Assign(userID: userID, clusterName: clusterName, requestOptions: requestOptions)
112112
return try execute(command)
113113
}
114-
114+
115115
// MARK: - Assign UserIDs
116-
116+
117117
/**
118118
Assign or move UserIDs to a ClusterName.
119119

@@ -132,7 +132,7 @@ public extension SearchClient {
132132
let command = Command.MultiCluster.User.BatchAssign(userIDs: userIDs, clusterName: clusterName, requestOptions: requestOptions)
133133
return execute(command, completion: completion)
134134
}
135-
135+
136136
/**
137137
Assign or move UserIDs to a ClusterName.
138138

@@ -149,9 +149,9 @@ public extension SearchClient {
149149
let command = Command.MultiCluster.User.BatchAssign(userIDs: userIDs, clusterName: clusterName, requestOptions: requestOptions)
150150
return try execute(command)
151151
}
152-
152+
153153
// MARK: - Get UserID
154-
154+
155155
/**
156156
Returns the UserID data stored in the mapping.
157157

@@ -168,7 +168,7 @@ public extension SearchClient {
168168
let command = Command.MultiCluster.User.Get(userID: userID, requestOptions: requestOptions)
169169
return execute(command, completion: completion)
170170
}
171-
171+
172172
/**
173173
Returns the UserID data stored in the mapping.
174174

@@ -183,9 +183,9 @@ public extension SearchClient {
183183
let command = Command.MultiCluster.User.Get(userID: userID, requestOptions: requestOptions)
184184
return try execute(command)
185185
}
186-
186+
187187
// MARK: - Get top UserID
188-
188+
189189
/**
190190
Get the top 10 ResponseUserID with the highest number of records per cluster.
191191
The data returned will usually be a few seconds behind real-time, because userID usage may take up to a few seconds to propagate to the different clusters.
@@ -199,7 +199,7 @@ public extension SearchClient {
199199
let command = Command.MultiCluster.User.GetTop(requestOptions: requestOptions)
200200
return execute(command, completion: completion)
201201
}
202-
202+
203203
/**
204204
Get the top 10 ResponseUserID with the highest number of records per cluster.
205205
The data returned will usually be a few seconds behind real-time, because userID usage may take up to a few seconds to propagate to the different clusters.
@@ -211,9 +211,9 @@ public extension SearchClient {
211211
let command = Command.MultiCluster.User.GetTop(requestOptions: requestOptions)
212212
return try execute(command)
213213
}
214-
214+
215215
// MARK: - Remove UserID
216-
216+
217217
/**
218218
Remove a UserID and its associated data from the multi-clusters.
219219

@@ -230,7 +230,7 @@ public extension SearchClient {
230230
let command = Command.MultiCluster.User.Remove(userID: userID, requestOptions: requestOptions)
231231
return execute(command, completion: completion)
232232
}
233-
233+
234234
/**
235235
Remove a UserID and its associated data from the multi-clusters.
236236

@@ -245,9 +245,9 @@ public extension SearchClient {
245245
let command = Command.MultiCluster.User.Remove(userID: userID, requestOptions: requestOptions)
246246
return try execute(command)
247247
}
248-
248+
249249
// MARK: - Search UserID
250-
250+
251251
/**
252252
Search for UserID.
253253

@@ -264,7 +264,7 @@ public extension SearchClient {
264264
let command = Command.MultiCluster.User.Search(userIDQuery: query, requestOptions: requestOptions)
265265
return execute(command, completion: completion)
266266
}
267-
267+
268268
/**
269269
Search for UserID.
270270

@@ -279,9 +279,9 @@ public extension SearchClient {
279279
let command = Command.MultiCluster.User.Search(userIDQuery: query, requestOptions: requestOptions)
280280
return try execute(command)
281281
}
282-
282+
283283
// MARK: - Has pending mapping
284-
284+
285285
/**
286286
- Parameter retrieveMappings: If set to true, retrieves HasPendingMappingResponse.clusters.
287287
- Parameter requestOptions: Configure request locally with RequestOptions
@@ -294,7 +294,7 @@ public extension SearchClient {
294294
let command = Command.MultiCluster.HasPendingMapping(retrieveMapping: retrieveMappings, requestOptions: requestOptions)
295295
return execute(command, completion: completion)
296296
}
297-
297+
298298
/**
299299
- Parameter retrieveMappings: If set to true, retrieves HasPendingMappingResponse.clusters.
300300
- Parameter requestOptions: Configure request locally with RequestOptions
@@ -305,5 +305,5 @@ public extension SearchClient {
305305
let command = Command.MultiCluster.HasPendingMapping(retrieveMapping: retrieveMappings, requestOptions: requestOptions)
306306
return try execute(command)
307307
}
308-
308+
309309
}

Sources/AlgoliaSearchClient/Helpers/Coding/Wrappers/BoolContainer.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import Foundation
1212
occasionally providing bool values in the form of String
1313
*/
1414
struct BoolContainer: RawRepresentable, Codable {
15-
15+
1616
let rawValue: Bool
17-
17+
1818
init(rawValue: Bool) {
1919
self.rawValue = rawValue
2020
}
21-
21+
2222
init(from decoder: Decoder) throws {
2323
let container = try decoder.singleValueContainer()
2424
if let boolValue = try? container.decode(Bool.self) {
@@ -31,5 +31,5 @@ struct BoolContainer: RawRepresentable, Codable {
3131
}
3232
throw DecodingError.dataCorruptedError(in: container, debugDescription: "Value cannot be decoded neither to Bool nor to String representing Bool value")
3333
}
34-
34+
3535
}

Sources/AlgoliaSearchClient/Helpers/Crypto/String+HMAC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import CommonCrypto
1414
#endif
1515

1616
extension String {
17-
17+
1818
func hmac256(withKey key: String) -> String {
1919
#if os(Linux)
2020
let key = SymmetricKey(data: Data(key.utf8))

Sources/AlgoliaSearchClient/Helpers/String/String+Wrapping.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import Foundation
99

1010
extension String {
11-
11+
1212
func wrappedInQuotes() -> String { "\"\(self)\"" }
1313
func wrappedInBrackets() -> String { "[\(self)]" }
14-
14+
1515
}

Sources/AlgoliaSearchClient/Index/Index+Synonym.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public extension Index {
112112
let command = Command.Synonym.SaveList(indexName: name, synonyms: synonyms, forwardToReplicas: forwardToReplicas, clearExistingSynonyms: replaceExistingSynonyms, requestOptions: requestOptions)
113113
return try execute(command)
114114
}
115-
115+
116116
/**
117117
Create or update multiple synonym.
118118
This method enables you to create or update one or more synonym in a single call.

Sources/AlgoliaSearchClient/Models/Internal/Path/Path.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct Path: PathComponent {
1717
return nil
1818
}
1919

20+
// swiftlint:disable unused_setter_value
2021
set {
2122
}
2223
}

Sources/AlgoliaSearchClient/Models/Internal/Path/PathComponent.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extension RootPath {
2727
get {
2828
return nil
2929
}
30-
30+
// swiftlint:disable unused_setter_value
3131
set { }
3232
}
3333

@@ -43,6 +43,8 @@ extension Never: PathComponent {
4343
get {
4444
return nil
4545
}
46+
47+
// swiftlint:disable unused_setter_value
4648
set {
4749
}
4850
}

Sources/AlgoliaSearchClient/Models/Rule/Rule+Alternatives.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ extension Rule.Alternatives: ExpressibleByBooleanLiteral {
4040
}
4141

4242
extension Rule.Alternatives: Decodable {
43-
43+
4444
public init(from decoder: Decoder) throws {
4545
let boolContainer = try BoolContainer(from: decoder)
4646
self = boolContainer.rawValue ? .true : .false
4747
}
48-
48+
4949
}

Sources/AlgoliaSearchClient/Models/Search/Hit/Hit.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public struct Hit<T: Codable> {
1616
public let snippetResult: TreeModel<SnippetResult>?
1717
public let highlightResult: TreeModel<HighlightResult>?
1818
public let rankingInfo: RankingInfo?
19-
public let geolocation: Point?
19+
public let geolocation: SingleOrList<Point>?
2020

2121
}
2222

@@ -39,7 +39,7 @@ extension Hit: Codable {
3939
self.snippetResult = try container.decodeIfPresent(TreeModel<SnippetResult>.self, forKey: .snippetResult)
4040
self.highlightResult = try container.decodeIfPresent(TreeModel<HighlightResult>.self, forKey: .highlightResult)
4141
self.rankingInfo = try container.decodeIfPresent(RankingInfo.self, forKey: .rankingInfo)
42-
self.geolocation = try container.decodeIfPresent(Point.self, forKey: .geolocation)
42+
self.geolocation = try? container.decodeIfPresent(SingleOrList<Point>.self, forKey: .geolocation)
4343
}
4444

4545
public func encode(to encoder: Encoder) throws {

0 commit comments

Comments
 (0)