File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
templates/dart/guides/search Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ { {> snippets/import} }
2+
3+ void savePopularRecords() async {
4+ {{> snippets/init} }
5+
6+ List<Map <String, dynamic >> records = [];
7+
8+ BrowseResponse? browseResponse;
9+ do {
10+ var browseParams = BrowseParamsObject(hitsPerPage: 1000, cursor: browseResponse?.cursor);
11+ browseResponse = await client.browse(
12+ indexName: " indexName" , browseParams: browseParams
13+ );
14+ for (var hit in browseResponse.hits) {
15+ final isPopular = hit[' nbFollowers' ] > 1000;
16+ final updatedProduct = {
17+ ...hit,
18+ ' isPopular' : isPopular,
19+ } ;
20+ records.add(updatedProduct);
21+ }
22+ } while (browseResponse.cursor != null);
23+
24+ var batchParams = BatchWriteParams(
25+ requests: records
26+ .map((record) => BatchRequest(
27+ action: Action.addObject,
28+ body: record,
29+ ))
30+ .toList());
31+ await { {#dynamicSnippet} }batchChunks{ {/dynamicSnippet} };
32+ }
You can’t perform that action at this time.
0 commit comments