Skip to content

Commit b820b09

Browse files
committed
feat(swift): savePopularRecords
1 parent ed8455e commit b820b09

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Foundation
2+
#if os(Linux) // For linux interop
3+
import FoundationNetworking
4+
#endif
5+
6+
import Core
7+
{{> snippets/import}}
8+
9+
func savePopularRecords() async throws {
10+
do {
11+
{{> snippets/init}}
12+
13+
var records: [Record] = []
14+
15+
try await client.browseObjects(indexName: indexName, browseParams: BrowseParamsObject(), aggregator: { (response: BrowseResponse<Record>) in
16+
records.append(contentsOf: response.hits.map {
17+
$0.nbFollowers < 1_000_000 ? $0 : Record(
18+
twitterHandle: $0.twitterHandle,
19+
nbFollowers: $0.nbFollowers,
20+
isPopular: true
21+
)
22+
})
23+
})
24+
25+
{{#dynamicSnippet}}saveObjectsRecords{{/dynamicSnippet}}
26+
} catch {
27+
print(error)
28+
}
29+
}

tests/CTS/guides/search.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,12 @@
3131
"indexName": "indexName",
3232
"searchParams": "$var: searchParams"
3333
}
34+
},
35+
"saveObjectsRecords": {
36+
"method": "saveObjects",
37+
"parameters": {
38+
"indexName": "indexName",
39+
"objects": "$var: records"
40+
}
3441
}
3542
}

0 commit comments

Comments
 (0)