File tree Expand file tree Collapse file tree 4 files changed +65
-4
lines changed Expand file tree Collapse file tree 4 files changed +65
-4
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ import kotlinx.serialization.json.JsonObject
2+
13{ {> snippets/import} }
24import 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+
415suspend fun setSettingsThenSaveObjects() {
516 playlists.forEach { playlist ->
617 // Fetch from your own data storage and with your own code
Original file line number Diff line number Diff line change @@ -6,12 +6,21 @@ import scala.concurrent.duration.Duration
66{ {> snippets/import} }
77import 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+
918def 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(
Original file line number Diff line number Diff line change @@ -6,12 +6,17 @@ import Foundation
66import 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+
914func 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)
You can’t perform that action at this time.
0 commit comments