setData method
Implementation
void setData(List<Map<String, dynamic>> data) {
// parse hits
List<Map<String, dynamic>> filteredResults = parseHits(data);
// filter results & remove duplicates if any
if (this.promotedData.length != 0) {
final List<String> ids =
this.promotedData.map((item) => item["_id"]) as List<String>;
if (ids.length != 0) {
filteredResults.where((item) {
// remove duplicate results
if (item["_id"] != null && ids.indexOf(item["_id"]) != -1) {
return false;
}
return true;
});
}
filteredResults = [
...this.promotedData.map((dataItem) =>
({...dataItem as Map<String, dynamic>, "_promoted": true})),
...filteredResults
];
}
// set data
if (this.parseResults != null) {
this.data = this.parseResults!(filteredResults, data);
} else {
this.data = filteredResults;
}
// Add click ids in data
this.data = withClickIds(this.data);
}