Skip to content

Commit

Permalink
feat(kotlin): savePopularRecords
Browse files Browse the repository at this point in the history
  • Loading branch information
Fluf22 committed Jan 24, 2025
1 parent 0b460d6 commit f48ecb7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions templates/kotlin/guides/search/savePopularRecords.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{> snippets/import}}
import com.algolia.client.model.search.*

suspend fun savePopularRecords() {
{{> snippets/init}}

var records: List<JsonObject> = listOf()

client.browseObjects(indexName, BrowseParamsObject(), aggregator = { response ->
records = records + response.hits.map { hit ->
val props = hit.additionalProperties ?: mapOf()
val nbFollowers = props["nbFollowers"].toString().toInt()
buildJsonObject {
put("twitterHandle", JsonPrimitive(props["twitterHandle"].toString()))
put("nbFollowers", JsonPrimitive(nbFollowers))
put("isPopular", JsonPrimitive(nbFollowers > 1000000))
}
}
})
client.{{#dynamicSnippet}}saveObjectsRecords{{/dynamicSnippet}}
}

0 comments on commit f48ecb7

Please sign in to comment.