couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "View_Snippets" by GregTappero
Date Wed, 21 Oct 2009 11:53:54 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The "View_Snippets" page has been changed by GregTappero.
The comment on this change is: remove faulty sort.
http://wiki.apache.org/couchdb/View_Snippets?action=diff&rev1=26&rev2=27

--------------------------------------------------

    * [[#aggregate_sum|Joining an aggregate sum along with related data ]]
    * [[#summary_stats|Computing simple summary statistics (min,max,mean,standard deviation)
]]
    * [[#interactive_couchdb|Interactive CouchDB Tutorial]]
-   * [[#sort_values_1|Sort values with reduce]]
+ 
  
  <<Anchor(common_mistakes)>>
  == Common mistakes ==
@@ -615, +615 @@

  == Interactive CouchDB Tutorial ==
  See [[http://labs.mudynamics.com/2009/04/03/interactive-couchdb/|this blog post]], which
is a CouchDB emulator (in JavaScript) that explains the basics of map/reduce, view collation
and querying CouchDB RESTfully.
  
- <<Anchor(sort_values_1)>>
- == Sort values with reduce ==
- 
- '''Map'''
- 
- {{{
- function(doc) {
-   emit(doc.name, doc.int_list);
- }
- }}}
- 
- "alice"   [1,5,3]
- 
- "bob"     [6,2,8]
- 
- "bob"     [5,6,4,12]
- 
- We want to get the following output:
- 
- "alice"	  [1, 3, 5]
- 
- "bob"     [2, 4, 5, 6, 6, 8, 12]
- 
- '''Reduce'''
- 
- {{{
- function(keys, values, rereduce)
- {
-     var int_list = new Array();
- 
-     if(!rereduce) {
-        
-         // values is the list of matching map keys (user) values (int_list).
-         
-         for(var v in values) {
- 
-             // we loop the int in int_list
- 
-             for (var t in values[v]) {
- 
-                 // append the int element to int_list
- 
-                 int_list.push(values[v][t]);
- 
-             }
-         }
-     }
-     else
-     {
-         // in rereduce values[0] is the output return int_list 
-         // of a previous reduce.
- 
-         int_list = values[0];  
- 
-         for(var v=1; v < values.length; v++) {
- 
-             for (var t in values[v]) {
- 
-                 int_list.push(values[v][t]);
- 
-             }
-         }
-     }
-  
-     function sort_int(a, b) {return a - b;}
- 
-     /* 
-     if sort_int is less than 0, place a before b.
-     if sort_int returns 0, leave a and b unchanged in respect to eachother.
-     if sort_int is greater than 0, place a after b.
-     */
- 
-     int_list.sort(sort_int);
-    
-     return int_list;
- }
- }}}
- 

Mime
View raw message