add distinct_ids to key_destinct
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 13 Mar 2013 19:28:57 +0000 (20:28 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 13 Mar 2013 19:29:00 +0000 (20:29 +0100)
This adds all ids of rows before destincting them

angular-server.pl

index aff04f0..3da071c 100755 (executable)
@@ -298,7 +298,16 @@ function(doc) {
        } elsif ( $format eq 'key_distinct' ) {
 
                my $found;
-               $json->{rows} = [ grep { ++$found->{ $_->{key} } == 1 } @{ $json->{rows} } ];
+               my @rows = grep {
+                       push @{ $found->{ $_->{key} } }, $_->{id};
+                       $#{ $found->{ $_->{key} } } == 0; # take just first registration
+               } @{ $json->{rows} };
+
+               $json->{rows} = [ map {
+                       $_->{distinct_ids} = $found->{ $_->{key} };
+                       $_;
+               } @rows ];
+
                $json->{distinct_rows} = scalar @{ $json->{rows} };
                warn "## distinct stats ", dump( $found );