Skip to content

Commit

Permalink
feat(dart): setSettingsThenSaveObjects (+ local vars)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fluf22 committed Jan 24, 2025
1 parent c0256e2 commit ac9a312
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
36 changes: 36 additions & 0 deletions templates/dart/guides/search/setSettingsThenSaveObjects.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{{> snippets/import}}

final playlists = []; // Your records

String getAppIDFor(String _) {
return ""; // Implement your own logic here
}

String getIndexingApiKeyFor(String _) {
return ""; // Implement your own logic here
}

void setSettingsThenSaveObjects() async {
for (final playlist in playlists) {
// Fetch from your own data storage and with your own code
// the associated application ID and API key for this user
final appId = getAppIDFor(playlist["user"]);
final apiKey = getIndexingApiKeyFor(playlist["user"]);
final client = SearchClient(appId: appId, apiKey: apiKey);
final settings = IndexSettings(
attributesForFaceting: ['filterOnly(userID)'],
);
await {{#dynamicSnippet}}setSettings{{/dynamicSnippet}};

final batchParams = BatchWriteParams(
requests: playlists
.map((record) => BatchRequest(
action: Action.addObject,
body: record,
))
.toList());
await {{#dynamicSnippet}}batchChunks{{/dynamicSnippet}};
}
}
11 changes: 11 additions & 0 deletions templates/kotlin/guides/search/setSettingsThenSaveObjects.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import kotlinx.serialization.json.JsonObject

{{> snippets/import}}
import com.algolia.client.model.search.*

val playlists = listOf<JsonObject>() // Your records

val getAppIDFor: (String) -> String = {
"" // Implement your own logic here
}
val getIndexingApiKeyFor: (String) -> String = {
"" // Implement your own logic here
}

suspend fun setSettingsThenSaveObjects() {
playlists.forEach { playlist ->
// Fetch from your own data storage and with your own code
Expand Down
13 changes: 11 additions & 2 deletions templates/scala/guides/search/setSettingsThenSaveObjects.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ import scala.concurrent.duration.Duration
{{> snippets/import}}
import algoliasearch.search.IndexSettings

val playlists: Seq[Map[String, Any]] = Seq()

val getAppIDFor: String => String = _ => {
"" // Implement your own logic here
}
val getIndexingApiKeyFor: String => String = _ => {
"" // Implement your own logic here
}

def setSettingsThenSaveObjects(): Future[Unit] = {
playlists.foreach { playlist =>
// Fetch from your own data storage and with your own code
// the associated application ID and API key for this user
val appID = getAppIDFor(playlist.user);
val apiKey = getIndexingApiKeyFor(playlist.user);
val appID = getAppIDFor(playlist("user").toString)
val apiKey = getIndexingApiKeyFor(playlist("user").toString)
val client = SearchClient(appID, apiKey)
val settings = IndexSettings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import Foundation
import Core
{{> snippets/import}}

let playlists: [[String: AnyCodable]] = [ /* Your records */ ]

let getAppIDFor = {(_: String) in ""} // Implement your own logic here
let getIndexingApiKeyFor = {(_: String) in ""} // Implement your own logic here

func setSettingsThenSaveObjects() async throws {
for playlist in playlists {
// Fetch from your own data storage and with your own code
// the associated application ID and API key for this user
let appID = getAppIDFor(playlist.user);
let apiKey = getIndexingApiKeyFor(playlist.user);
let appID = getAppIDFor(playlist["user"]?.value as! String);
let apiKey = getIndexingApiKeyFor(playlist["user"]?.value as! String);
do {
let client = try SearchClient(appID: appID, apiKey: apiKey)
Expand Down

0 comments on commit ac9a312

Please sign in to comment.