Skip to content

Commit 410c34a

Browse files
refactor: rename replaceExistingSynonyms into clearExistingSynonyms (#696)
1 parent 7db6835 commit 410c34a

File tree

5 files changed

+77
-17
lines changed

5 files changed

+77
-17
lines changed

Sources/AlgoliaSearchClient/Command/Command+Synonym.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension Command {
3434
init(indexName: IndexName, synonyms: [AlgoliaSearchClient.Synonym], forwardToReplicas: Bool?, clearExistingSynonyms: Bool?, requestOptions: RequestOptions?) {
3535
var parameters: [HTTPParameterKey: String] = [:]
3636
forwardToReplicas.flatMap { parameters[.forwardToReplicas] = String($0) }
37-
clearExistingSynonyms.flatMap { parameters[.clearExistingSynonyms] = String($0) }
37+
clearExistingSynonyms.flatMap { parameters[.replaceExistingSynonyms] = String($0) }
3838
self.requestOptions = requestOptions.updateOrCreate(parameters)
3939
let path = .indexesV1 >>> .index(indexName) >>> .synonyms >>> SynonymCompletion.batch
4040
urlRequest = .init(method: .post, path: path, body: synonyms.httpBody, requestOptions: self.requestOptions)

Sources/AlgoliaSearchClient/Index/Index+Synonym.swift

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public extension Index {
4242
By making this true, the method will also send the synonym to all replicas.
4343
Thus, if you want to forward your synonyms to replicas you will need to specify that.
4444
- Parameter requestOptions: Configure request locally with RequestOptions
45-
- Returns: SynonymRevision object
45+
- Returns: SynonymRevision object
4646
*/
4747
@discardableResult func saveSynonym(_ synonym: Synonym,
4848
forwardToReplicas: Bool? = nil,
@@ -74,9 +74,10 @@ public extension Index {
7474
- Parameter completion: Result completion
7575
- Returns: Launched asynchronous operation
7676
*/
77+
@available(*, deprecated, renamed: "saveSynonyms(_:forwardToReplicas:clearExistingSynonyms:requestOptions:completion:)")
7778
@discardableResult func saveSynonyms(_ synonyms: [Synonym],
7879
forwardToReplicas: Bool? = nil,
79-
replaceExistingSynonyms: Bool? = nil,
80+
replaceExistingSynonyms: Bool?,
8081
requestOptions: RequestOptions? = nil,
8182
completion: @escaping ResultCallback<IndexRevision>) -> Operation {
8283
let command = Command.Synonym.SaveList(indexName: name, synonyms: synonyms, forwardToReplicas: forwardToReplicas, clearExistingSynonyms: replaceExistingSynonyms, requestOptions: requestOptions)
@@ -101,15 +102,74 @@ public extension Index {
101102
This parameter tells the engine to delete all existing synonyms before recreating a new list from the synonyms listed in the current call.
102103
This is the only way to avoid having no synonyms, ensuring that your index will always provide a full list of synonyms to your end-users.
103104
- Parameter requestOptions: Configure request locally with RequestOptions
104-
- Returns: SynonymRevision object
105+
- Returns: IndexRevision object
105106
*/
107+
@available(*, deprecated, renamed: "saveSynonyms(_:forwardToReplicas:clearExistingSynonyms:requestOptions:)")
106108
@discardableResult func saveSynonyms(_ synonyms: [Synonym],
107109
forwardToReplicas: Bool? = nil,
108-
replaceExistingSynonyms: Bool? = nil,
110+
replaceExistingSynonyms: Bool?,
109111
requestOptions: RequestOptions? = nil) throws -> WaitableWrapper<IndexRevision> {
110112
let command = Command.Synonym.SaveList(indexName: name, synonyms: synonyms, forwardToReplicas: forwardToReplicas, clearExistingSynonyms: replaceExistingSynonyms, requestOptions: requestOptions)
111113
return try execute(command)
112114
}
115+
116+
/**
117+
Create or update multiple synonym.
118+
This method enables you to create or update one or more synonym in a single call.
119+
You can also recreate your entire set of synonym by using the clearExistingSynonyms parameter.
120+
Note that each synonym object counts as a single indexing operation.
121+
122+
- Parameter synonyms: List of synonym to save.
123+
- Parameter forwardToReplicas: By default, this method applies only to the specified index.
124+
By making this true, the method will also send the synonym to all replicas.
125+
Thus, if you want to forward your synonyms to replicas you will need to specify that.
126+
- Parameter clearExistingSynonyms: Forces the engine to replace all synonyms, using an atomic save.
127+
Normally, to replace all synonyms on an index, you would first clear the synonyms, using clearAllSynonyms, and then create a new list.
128+
However, between the clear and the add, your index will have no synonyms.
129+
This is where clearExistingSynonyms comes into play.
130+
By adding this parameter, you do not need to use clearSynonyms, it’s done for you.
131+
This parameter tells the engine to delete all existing synonyms before recreating a new list from the synonyms listed in the current call.
132+
This is the only way to avoid having no synonyms, ensuring that your index will always provide a full list of synonyms to your end-users.
133+
- Parameter requestOptions: Configure request locally with RequestOptions
134+
- Parameter completion: Result completion
135+
- Returns: Launched asynchronous operation
136+
*/
137+
@discardableResult func saveSynonyms(_ synonyms: [Synonym],
138+
forwardToReplicas: Bool? = nil,
139+
clearExistingSynonyms: Bool? = nil,
140+
requestOptions: RequestOptions? = nil,
141+
completion: @escaping ResultCallback<IndexRevision>) -> Operation {
142+
let command = Command.Synonym.SaveList(indexName: name, synonyms: synonyms, forwardToReplicas: forwardToReplicas, clearExistingSynonyms: clearExistingSynonyms, requestOptions: requestOptions)
143+
return execute(command, completion: completion)
144+
}
145+
146+
/**
147+
Create or update multiple synonym.
148+
This method enables you to create or update one or more synonym in a single call.
149+
You can also recreate your entire set of synonym by using the clearExistingSynonyms parameter.
150+
Note that each synonym object counts as a single indexing operation.
151+
152+
- Parameter synonyms: List of synonym to save.
153+
- Parameter forwardToReplicas: By default, this method applies only to the specified index.
154+
By making this true, the method will also send the synonym to all replicas.
155+
Thus, if you want to forward your synonyms to replicas you will need to specify that.
156+
- Parameter clearExistingSynonyms: Forces the engine to replace all synonyms, using an atomic save.
157+
Normally, to replace all synonyms on an index, you would first clear the synonyms, using clearAllSynonyms, and then create a new list.
158+
However, between the clear and the add, your index will have no synonyms.
159+
This is where clearExistingSynonyms comes into play.
160+
By adding this parameter, you do not need to use clearSynonyms, it’s done for you.
161+
This parameter tells the engine to delete all existing synonyms before recreating a new list from the synonyms listed in the current call.
162+
This is the only way to avoid having no synonyms, ensuring that your index will always provide a full list of synonyms to your end-users.
163+
- Parameter requestOptions: Configure request locally with RequestOptions
164+
- Returns: IndexRevision object
165+
*/
166+
@discardableResult func saveSynonyms(_ synonyms: [Synonym],
167+
forwardToReplicas: Bool? = nil,
168+
clearExistingSynonyms: Bool? = nil,
169+
requestOptions: RequestOptions? = nil) throws -> WaitableWrapper<IndexRevision> {
170+
let command = Command.Synonym.SaveList(indexName: name, synonyms: synonyms, forwardToReplicas: forwardToReplicas, clearExistingSynonyms: clearExistingSynonyms, requestOptions: requestOptions)
171+
return try execute(command)
172+
}
113173

114174
// MARK: - Get synonym
115175

@@ -133,7 +193,7 @@ public extension Index {
133193

134194
- Parameter objectID: ObjectID of the synonym to retrieve.
135195
- Parameter requestOptions: Configure request locally with RequestOptions
136-
- Returns: Synonym object
196+
- Returns: Synonym object
137197
*/
138198
@discardableResult func getSynonym(withID objectID: ObjectID,
139199
requestOptions: RequestOptions? = nil) throws -> Synonym {
@@ -164,7 +224,7 @@ public extension Index {
164224

165225
- Parameter objectID: ObjectID of the synonym to delete.
166226
- Parameter requestOptions: Configure request locally with RequestOptions
167-
- Returns: DeletionIndex object
227+
- Returns: IndexDeletion object
168228
*/
169229
@discardableResult func deleteSynonym(withID objectID: ObjectID,
170230
forwardToReplicas: Bool? = nil,
@@ -209,7 +269,7 @@ public extension Index {
209269
Remove all synonyms from an index. This is a convenience method to delete all synonyms at once.
210270
This Clear All method should not be used on a production index to push a new list of synonyms because it will
211271
result in a short down period during which the index would have no synonyms at all.
212-
Instead, use the saveSynonyms method (with replaceExistingSynonyms set to true) to atomically replace all synonyms of an index with no down time.
272+
Instead, use the saveSynonyms method (with clearExistingSynonyms set to true) to atomically replace all synonyms of an index with no down time.
213273

214274
- Parameter forwardToReplicas: Also replace synonyms on replicas.
215275
- Parameter requestOptions: Configure request locally with RequestOptions
@@ -227,11 +287,11 @@ public extension Index {
227287
Remove all synonyms from an index. This is a convenience method to delete all synonyms at once.
228288
This Clear All method should not be used on a production index to push a new list of synonyms because it will
229289
result in a short down period during which the index would have no synonyms at all.
230-
Instead, use the saveSynonyms method (with replaceExistingSynonyms set to true) to atomically replace all synonyms of an index with no down time.
290+
Instead, use the saveSynonyms method (with clearExistingSynonyms set to true) to atomically replace all synonyms of an index with no down time.
231291

232292
- Parameter forwardToReplicas: Also replace synonyms on replicas.
233293
- Parameter requestOptions: Configure request locally with RequestOptions
234-
- Returns: RevisionIndex object
294+
- Returns: IndexRevision object
235295
*/
236296
@discardableResult func clearSynonyms(forwardToReplicas: Bool? = nil,
237297
requestOptions: RequestOptions? = nil) throws -> WaitableWrapper<IndexRevision> {
@@ -256,7 +316,7 @@ public extension Index {
256316
forwardToReplicas: Bool? = nil,
257317
requestOptions: RequestOptions? = nil,
258318
completion: @escaping ResultCallback<IndexRevision>) -> Operation {
259-
saveSynonyms(synonyms, forwardToReplicas: forwardToReplicas, replaceExistingSynonyms: true, requestOptions: requestOptions, completion: completion)
319+
saveSynonyms(synonyms, forwardToReplicas: forwardToReplicas, clearExistingSynonyms: true, requestOptions: requestOptions, completion: completion)
260320
}
261321

262322
/**
@@ -267,12 +327,12 @@ public extension Index {
267327
- Parameter synonyms: A list of synonym.
268328
- Parameter forwardToReplicas: Also replace synonyms on replicas.
269329
- Parameter requestOptions: Configure request locally with RequestOptions
270-
- Returns: RevisionIndex object
330+
- Returns: IndexRevision object
271331
*/
272332
@discardableResult func replaceAllSynonyms(with synonyms: [Synonym],
273333
forwardToReplicas: Bool? = nil,
274334
requestOptions: RequestOptions? = nil) throws -> WaitableWrapper<IndexRevision> {
275-
try saveSynonyms(synonyms, forwardToReplicas: forwardToReplicas, replaceExistingSynonyms: true, requestOptions: requestOptions)
335+
try saveSynonyms(synonyms, forwardToReplicas: forwardToReplicas, clearExistingSynonyms: true, requestOptions: requestOptions)
276336
}
277337

278338
}

Sources/AlgoliaSearchClient/Models/Common/RequestOptions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extension HTTPParameterKey {
8686
static var attributesToRetreive: HTTPParameterKey { #function }
8787
static var forwardToReplicas: HTTPParameterKey { #function }
8888
static var clearExistingRules: HTTPParameterKey { #function }
89-
static var clearExistingSynonyms: HTTPParameterKey { #function }
89+
static var replaceExistingSynonyms: HTTPParameterKey { #function }
9090
static var createIfNotExists: HTTPParameterKey { #function }
9191
static var cursor: HTTPParameterKey { #function }
9292
static var indexName: HTTPParameterKey { #function }

Tests/AlgoliaSearchClientTests/Doc/Methods/SynonymsSnippets.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ extension SynonymsSnippets {
9393
index.saveSynonyms(
9494
_ #{synonyms}: __[Synonym]__,
9595
#{forwardToReplicas}: __Bool?__ = nil,
96-
#{replaceExistingSynonyms}: __Bool?__ = nil,
96+
#{clearExistingSynonyms}: __Bool?__ = nil,
9797
requestOptions: __RequestOptions?__ = nil,
9898
completion: __Result<IndexRevision> -> Void__
9999
)
@@ -105,7 +105,7 @@ extension SynonymsSnippets {
105105
.multiWay(objectID: "myID2", synonyms: ["street", "st"])
106106
]
107107

108-
index.saveSynonyms(synonyms, forwardToReplicas: true, replaceExistingSynonyms: false) { result in
108+
index.saveSynonyms(synonyms, forwardToReplicas: true, clearExistingSynonyms: false) { result in
109109
if case .success(let response) = result {
110110
print("Response: \(response)")
111111
}

Tests/AlgoliaSearchClientTests/Unit/Command/SynonymCommandTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class SynonymCommandTests: XCTestCase, AlgoliaCommandTest {
8989
queryItems: [
9090
.init(name: "testParameter", value: "testParameterValue"),
9191
.init(name: "forwardToReplicas", value: "true"),
92-
.init(name: "clearExistingSynonyms", value: "true")
92+
.init(name: "replaceExistingSynonyms", value: "true")
9393
],
9494
body: synonyms.httpBody,
9595
requestOptions: test.requestOptions)

0 commit comments

Comments
 (0)