authors table view
[angular-drzb] / angular-server.pl
index 0e38168..94c84ad 100755 (executable)
@@ -262,7 +262,29 @@ if ( doc.user.organization != '' ) {
 }
                                        }q|,
                                        reduce => q| function(keys,values,rereduce) { return sum(values); } |,
-                               }
+                               },
+                               authors => {
+                                       map => q|
+function(doc) {
+  if ( doc.work.persons ) {
+    doc.work.persons.forEach( function(person) {
+      emit(person.surname+person.firstname ,
+        person
+      );
+    });
+  }
+  if ( doc.work.symposium_works ) {
+    doc.work.symposium_works.forEach( function(work) {
+      work.persons.forEach( function(person) {
+        emit(person.surname+person.firstname ,
+          person
+        );
+      });
+    });
+  }
+}
+                                       |,
+                               },
                        }
                };
                $json = _couchdb_get($url)
@@ -271,6 +293,17 @@ if ( doc.user.organization != '' ) {
 
        if ( $format eq 'key_array' ) { # array of keys sorted by value
                $json->{rows} = [ map { $_->{key} } sort { $b->{value} <=> $a->{value} } @{ $json->{rows} } ];
+       } elsif ( $format eq 'key_distinct' ) {
+
+               my $found;
+               $json->{rows} = [ grep { $found->{ $_->{key} }++ == 1 } @{ $json->{rows} } ];
+               $json->{distinct_rows} = scalar @{ $json->{rows} };
+               warn "## distinct stats ", dump( $found );
+
+       } elsif ( $format ) {
+
+               die "unknown format: $format";
+
        }
 
        $view_cache->{$url}->{time} = time();