Skip to content

Commit 51549a1

Browse files
committed
feat(dart): setSettingsThenSaveObjects (+ local vars)
1 parent 04f58eb commit 51549a1

File tree

4 files changed

+65
-4
lines changed

4 files changed

+65
-4
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{{> snippets/import}}
2+
3+
final playlists = []; // Your records
4+
5+
String getAppIDFor(String _) {
6+
return ""; // Implement your own logic here
7+
}
8+
9+
String getIndexingApiKeyFor(String _) {
10+
return ""; // Implement your own logic here
11+
}
12+
13+
void setSettingsThenSaveObjects() async {
14+
for (final playlist in playlists) {
15+
// Fetch from your own data storage and with your own code
16+
// the associated application ID and API key for this user
17+
final appId = getAppIDFor(playlist["user"]);
18+
final apiKey = getIndexingApiKeyFor(playlist["user"]);
19+
20+
final client = SearchClient(appId: appId, apiKey: apiKey);
21+
final settings = IndexSettings(
22+
attributesForFaceting: ['filterOnly(userID)'],
23+
);
24+
25+
await {{#dynamicSnippet}}setSettings{{/dynamicSnippet}};
26+
27+
final batchParams = BatchWriteParams(
28+
requests: playlists
29+
.map((record) => BatchRequest(
30+
action: Action.addObject,
31+
body: record,
32+
))
33+
.toList());
34+
await {{#dynamicSnippet}}batchChunks{{/dynamicSnippet}};
35+
}
36+
}

templates/kotlin/guides/search/setSettingsThenSaveObjects.mustache

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
import kotlinx.serialization.json.JsonObject
2+
13
{{> snippets/import}}
24
import com.algolia.client.model.search.*
35

6+
val playlists = listOf<JsonObject>() // Your records
7+
8+
val getAppIDFor: (String) -> String = {
9+
"" // Implement your own logic here
10+
}
11+
val getIndexingApiKeyFor: (String) -> String = {
12+
"" // Implement your own logic here
13+
}
14+
415
suspend fun setSettingsThenSaveObjects() {
516
playlists.forEach { playlist ->
617
// Fetch from your own data storage and with your own code

templates/scala/guides/search/setSettingsThenSaveObjects.mustache

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@ import scala.concurrent.duration.Duration
66
{{> snippets/import}}
77
import algoliasearch.search.IndexSettings
88

9+
val playlists: Seq[Map[String, Any]] = Seq()
10+
11+
val getAppIDFor: String => String = _ => {
12+
"" // Implement your own logic here
13+
}
14+
val getIndexingApiKeyFor: String => String = _ => {
15+
"" // Implement your own logic here
16+
}
17+
918
def setSettingsThenSaveObjects(): Future[Unit] = {
1019
playlists.foreach { playlist =>
1120
// Fetch from your own data storage and with your own code
1221
// the associated application ID and API key for this user
13-
val appID = getAppIDFor(playlist.user);
14-
val apiKey = getIndexingApiKeyFor(playlist.user);
22+
val appID = getAppIDFor(playlist("user").toString)
23+
val apiKey = getIndexingApiKeyFor(playlist("user").toString)
1524
1625
val client = SearchClient(appID, apiKey)
1726
val settings = IndexSettings(

templates/swift/guides/search/setSettingsThenSaveObjects.mustache

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ import Foundation
66
import Core
77
{{> snippets/import}}
88

9+
let playlists: [[String: AnyCodable]] = [ /* Your records */ ]
10+
11+
let getAppIDFor = {(_: String) in ""} // Implement your own logic here
12+
let getIndexingApiKeyFor = {(_: String) in ""} // Implement your own logic here
13+
914
func setSettingsThenSaveObjects() async throws {
1015
for playlist in playlists {
1116
// Fetch from your own data storage and with your own code
1217
// the associated application ID and API key for this user
13-
let appID = getAppIDFor(playlist.user);
14-
let apiKey = getIndexingApiKeyFor(playlist.user);
18+
let appID = getAppIDFor(playlist["user"]?.value as! String);
19+
let apiKey = getIndexingApiKeyFor(playlist["user"]?.value as! String);
1520
1621
do {
1722
let client = try SearchClient(appID: appID, apiKey: apiKey)

0 commit comments

Comments
 (0)