Skip to content

Commit 3b56b20

Browse files
algolia-botben-kalmusFluf22
committed
feat(specs): add sortBy query param and sortingStrategy (generated)
algolia/api-clients-automation#5686 Co-authored-by: algolia-bot <[email protected]> Co-authored-by: Ben Kalmus <[email protected]> Co-authored-by: Thomas Raffray <[email protected]>
1 parent f3f16fe commit 3b56b20

File tree

3 files changed

+116
-12
lines changed

3 files changed

+116
-12
lines changed

Sources/Composition/CompositionClient.swift

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,4 +1231,77 @@ open class CompositionClient {
12311231
useReadTransporter: true
12321232
)
12331233
}
1234+
1235+
/// - parameter compositionID: (path) Unique Composition ObjectID.
1236+
/// - parameter requestBody: (body)
1237+
/// - returns: TaskIDResponse
1238+
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
1239+
open func updateSortingStrategyComposition(
1240+
compositionID: String,
1241+
requestBody: [String: String],
1242+
requestOptions: RequestOptions? = nil
1243+
) async throws -> TaskIDResponse {
1244+
let response: Response<TaskIDResponse> = try await updateSortingStrategyCompositionWithHTTPInfo(
1245+
compositionID: compositionID,
1246+
requestBody: requestBody,
1247+
requestOptions: requestOptions
1248+
)
1249+
1250+
guard let body = response.body else {
1251+
throw AlgoliaError.missingData
1252+
}
1253+
1254+
return body
1255+
}
1256+
1257+
// Updates the \"sortingStrategy\" field of an existing composition. This endpoint allows you to create a new
1258+
// sorting strategy mapping or replace the currently configured one. The provided sorting indices MUST be associated
1259+
// indices or replicas of the main targeted index. WARNING: This endpoint cannot validate if the sort index is
1260+
// related to the composition's main index. Validation will fail at runtime if the index you updated is not
1261+
// related! The update is applied to the specified composition within the current Algolia application and returns a
1262+
// taskID that can be used to track the operation’s completion.
1263+
// Required API Key ACLs:
1264+
// - editSettings
1265+
//
1266+
// - parameter compositionID: (path) Unique Composition ObjectID.
1267+
//
1268+
// - parameter requestBody: (body)
1269+
// - returns: RequestBuilder<TaskIDResponse>
1270+
1271+
open func updateSortingStrategyCompositionWithHTTPInfo(
1272+
compositionID: String,
1273+
requestBody: [String: String],
1274+
requestOptions userRequestOptions: RequestOptions? = nil
1275+
) async throws -> Response<TaskIDResponse> {
1276+
guard !compositionID.isEmpty else {
1277+
throw AlgoliaError.invalidArgument("compositionID", "updateSortingStrategyComposition")
1278+
}
1279+
1280+
var resourcePath = "/1/compositions/{compositionID}/sortingStrategy"
1281+
let compositionIDPreEscape = "\(APIHelper.mapValueToPathItem(compositionID))"
1282+
let compositionIDPostEscape = compositionIDPreEscape
1283+
.addingPercentEncoding(withAllowedCharacters: .urlPathAlgoliaAllowed) ?? ""
1284+
resourcePath = resourcePath.replacingOccurrences(
1285+
of: "{compositionID}",
1286+
with: compositionIDPostEscape,
1287+
options: .literal,
1288+
range: nil
1289+
)
1290+
let body = requestBody
1291+
let queryParameters: [String: Any?]? = nil
1292+
1293+
let nillableHeaders: [String: Any?]? = nil
1294+
1295+
let headers = APIHelper.rejectNilHeaders(nillableHeaders)
1296+
1297+
return try await self.transporter.send(
1298+
method: "POST",
1299+
path: resourcePath,
1300+
data: body,
1301+
requestOptions: RequestOptions(
1302+
headers: headers,
1303+
queryParameters: queryParameters
1304+
) + userRequestOptions
1305+
)
1306+
}
12341307
}

Sources/Composition/Models/Composition.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,34 @@ public struct Composition: Codable, JSONEncodable {
1414
/// Composition description.
1515
public var description: String?
1616
public var behavior: CompositionBehavior
17+
/// A mapping of sorting labels to the indices (or replicas) that implement those sorting rules. The sorting indices
18+
/// MUST be related to the associated main targeted index in the composition. Each key is the label your frontend
19+
/// sends at runtime (for example, \"Price (asc)\"), and each value is the name of the index that should be queried
20+
/// when that label is selected. When a request includes a \"sortBy\" parameter, the platform looks up the
21+
/// corresponding index in this mapping and uses it to execute the query. The main targeted index is replaced with
22+
/// the sorting strategy index it is mapped to. Up to 20 sorting strategies can be defined.
23+
public var sortingStrategy: [String: String]?
1724

18-
public init(objectID: String, name: String, description: String? = nil, behavior: CompositionBehavior) {
25+
public init(
26+
objectID: String,
27+
name: String,
28+
description: String? = nil,
29+
behavior: CompositionBehavior,
30+
sortingStrategy: [String: String]? = nil
31+
) {
1932
self.objectID = objectID
2033
self.name = name
2134
self.description = description
2235
self.behavior = behavior
36+
self.sortingStrategy = sortingStrategy
2337
}
2438

2539
public enum CodingKeys: String, CodingKey, CaseIterable {
2640
case objectID
2741
case name
2842
case description
2943
case behavior
44+
case sortingStrategy
3045
}
3146

3247
// Encodable protocol methods
@@ -37,6 +52,7 @@ public struct Composition: Codable, JSONEncodable {
3752
try container.encode(self.name, forKey: .name)
3853
try container.encodeIfPresent(self.description, forKey: .description)
3954
try container.encode(self.behavior, forKey: .behavior)
55+
try container.encodeIfPresent(self.sortingStrategy, forKey: .sortingStrategy)
4056
}
4157
}
4258

@@ -45,7 +61,8 @@ extension Composition: Equatable {
4561
lhs.objectID == rhs.objectID &&
4662
lhs.name == rhs.name &&
4763
lhs.description == rhs.description &&
48-
lhs.behavior == rhs.behavior
64+
lhs.behavior == rhs.behavior &&
65+
lhs.sortingStrategy == rhs.sortingStrategy
4966
}
5067
}
5168

@@ -55,5 +72,6 @@ extension Composition: Hashable {
5572
hasher.combine(self.name.hashValue)
5673
hasher.combine(self.description?.hashValue)
5774
hasher.combine(self.behavior.hashValue)
75+
hasher.combine(self.sortingStrategy?.hashValue)
5876
}
5977
}

Sources/Composition/Models/CompositionParams.swift

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ public struct CompositionParams: Codable, JSONEncodable {
8080
public var page: Int?
8181
/// Search query.
8282
public var query: String?
83-
/// Relevancy threshold below which less relevant results aren't included in the results You can only set
84-
/// `relevancyStrictness` on [virtual replica indices](https://www.algolia.com/doc/guides/managing-results/refine-results/sorting/in-depth/replicas/#what-are-virtual-replicas).
85-
/// Use this setting to strike a balance between the relevance and number of returned results.
86-
public var relevancyStrictness: Int?
8783
/// Languages for language-specific query processing steps such as plurals, stop-word removal, and word-detection
8884
/// dictionaries This setting sets a default list of languages used by the `removeStopWords` and `ignorePlurals`
8985
/// settings. This setting also sets a dictionary for word detection in the logogram-based [CJK](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/normalization/#normalization-for-logogram-based-languages-cjk)
@@ -92,9 +88,20 @@ public struct CompositionParams: Codable, JSONEncodable {
9288
/// or the languages you specified with the `ignorePlurals` or `removeStopWords` parameters. This can lead to
9389
/// unexpected search results. For more information, see [Language-specific configuration](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/language-specific-configurations).
9490
public var queryLanguages: [CompositionSupportedLanguage]?
91+
/// Relevancy threshold below which less relevant results aren't included in the results You can only set
92+
/// `relevancyStrictness` on [virtual replica indices](https://www.algolia.com/doc/guides/managing-results/refine-results/sorting/in-depth/replicas/#what-are-virtual-replicas).
93+
/// Use this setting to strike a balance between the relevance and number of returned results.
94+
public var relevancyStrictness: Int?
9595
/// Assigns a rule context to the run query [Rule contexts](https://www.algolia.com/doc/guides/managing-results/rules/rules-overview/how-to/customize-search-results-by-platform/#whats-a-context)
9696
/// are strings that you can use to trigger matching rules.
9797
public var ruleContexts: [String]?
98+
/// Indicates which sorting strategy to apply for the request. The value must match one of the labels defined in the
99+
/// \"sortingStrategy\" mapping. For example, \"Price (asc)\", see Upsert Composition. At runtime, this label is
100+
/// used to look up the corresponding index or replica configured in \"sortingStrategy\", and the query is executed
101+
/// using that index instead of main's. In addition to \"sortingStrategy\", this parameter is also used to apply a
102+
/// matching Composition Rule that contains a condition defined to trigger on \"sortBy\", see Composition Rules. If
103+
/// no value is provided or an invalid value, no sorting strategy is applied.
104+
public var sortBy: String?
98105
/// Unique pseudonymous or anonymous user identifier. This helps with analytics and click and conversion events.
99106
/// For more information, see [user token](https://www.algolia.com/doc/guides/sending-events/concepts/usertoken).
100107
public var userToken: String?
@@ -125,9 +132,10 @@ public struct CompositionParams: Codable, JSONEncodable {
125132
optionalFilters: CompositionOptionalFilters? = nil,
126133
page: Int? = nil,
127134
query: String? = nil,
128-
relevancyStrictness: Int? = nil,
129135
queryLanguages: [CompositionSupportedLanguage]? = nil,
136+
relevancyStrictness: Int? = nil,
130137
ruleContexts: [String]? = nil,
138+
sortBy: String? = nil,
131139
userToken: String? = nil
132140
) {
133141
self.analytics = analytics
@@ -155,9 +163,10 @@ public struct CompositionParams: Codable, JSONEncodable {
155163
self.optionalFilters = optionalFilters
156164
self.page = page
157165
self.query = query
158-
self.relevancyStrictness = relevancyStrictness
159166
self.queryLanguages = queryLanguages
167+
self.relevancyStrictness = relevancyStrictness
160168
self.ruleContexts = ruleContexts
169+
self.sortBy = sortBy
161170
self.userToken = userToken
162171
}
163172

@@ -187,9 +196,10 @@ public struct CompositionParams: Codable, JSONEncodable {
187196
case optionalFilters
188197
case page
189198
case query
190-
case relevancyStrictness
191199
case queryLanguages
200+
case relevancyStrictness
192201
case ruleContexts
202+
case sortBy
193203
case userToken
194204
}
195205

@@ -222,9 +232,10 @@ public struct CompositionParams: Codable, JSONEncodable {
222232
try container.encodeIfPresent(self.optionalFilters, forKey: .optionalFilters)
223233
try container.encodeIfPresent(self.page, forKey: .page)
224234
try container.encodeIfPresent(self.query, forKey: .query)
225-
try container.encodeIfPresent(self.relevancyStrictness, forKey: .relevancyStrictness)
226235
try container.encodeIfPresent(self.queryLanguages, forKey: .queryLanguages)
236+
try container.encodeIfPresent(self.relevancyStrictness, forKey: .relevancyStrictness)
227237
try container.encodeIfPresent(self.ruleContexts, forKey: .ruleContexts)
238+
try container.encodeIfPresent(self.sortBy, forKey: .sortBy)
228239
try container.encodeIfPresent(self.userToken, forKey: .userToken)
229240
}
230241
}
@@ -256,9 +267,10 @@ extension CompositionParams: Equatable {
256267
lhs.optionalFilters == rhs.optionalFilters &&
257268
lhs.page == rhs.page &&
258269
lhs.query == rhs.query &&
259-
lhs.relevancyStrictness == rhs.relevancyStrictness &&
260270
lhs.queryLanguages == rhs.queryLanguages &&
271+
lhs.relevancyStrictness == rhs.relevancyStrictness &&
261272
lhs.ruleContexts == rhs.ruleContexts &&
273+
lhs.sortBy == rhs.sortBy &&
262274
lhs.userToken == rhs.userToken
263275
}
264276
}
@@ -290,9 +302,10 @@ extension CompositionParams: Hashable {
290302
hasher.combine(self.optionalFilters?.hashValue)
291303
hasher.combine(self.page?.hashValue)
292304
hasher.combine(self.query?.hashValue)
293-
hasher.combine(self.relevancyStrictness?.hashValue)
294305
hasher.combine(self.queryLanguages?.hashValue)
306+
hasher.combine(self.relevancyStrictness?.hashValue)
295307
hasher.combine(self.ruleContexts?.hashValue)
308+
hasher.combine(self.sortBy?.hashValue)
296309
hasher.combine(self.userToken?.hashValue)
297310
}
298311
}

0 commit comments

Comments
 (0)