On Mar 23, 2016, at 4:19 AM, Brendan Duddridge <bren...@gmail.com> wrote:
How can I emit unique values in my map block? Is there a way to do that easily or will it require keeping an array of already emitted values, ensuring that I don't emit another one with the same value? I just don't want duplicate keys in my view.
NSMutableDictionary *existingValues = [[NSMutableDictionary alloc] init];
[fieldValuesView setMapBlock: MAPBLOCK({
NSDictionary *valuesData = doc[@"values"];
if (valuesData) {
NSString *value = valuesData[weakSelf.field.document.documentID];
if (!existingValues[value]) {
if ([NSString ts_isNotEmptyString:value]) {
emit(value, nil);
existingValues[value] = @YES;
}
}
}
}) reduceBlock:^id(NSArray *keys, NSArray *values, BOOL rereduce) {
return @(keys.count);
} version: versionNumber];
On Mar 23, 2016, at 3:57 PM, Brendan Duddridge <bren...@gmail.com> wrote:
For example, I want to display a list of movie genres that's derived from a list of movies. Many movies have the same genre. But I wanted a view that contained the keys that were the unique Genre names of all the movies in the database.
On Mar 23, 2016, at 7:49 PM, Brendan Duddridge <bren...@gmail.com> wrote:
But then my map view table would actually contain all this duplicate data taking up space that it didn't need to?
|
|
NSString* artist = doc[@"Artist"]; | |
NSString* name = doc[@"Name"]; | |
if (artist && name) { | |
if ([doc[@"Compilation"] boolValue]) { | |
artist = @"-Compilations-"; | |
} | |
emit(@[artist, | |
doc[@"Album"] ?: [NSNull null], | |
doc[@"Track Number"] ?: [NSNull null], | |
name, | |
@1], | |
doc[@"Total Time"]); | |
} |