Author: rick
Date: 2010-03-17 23:43:25 +0100 (Wed, 17 Mar 2010)
New Revision: 28595

Added:
   plugins/sfCouchPlugin/trunk/config/couchdb/alldocs_map.js
   plugins/sfCouchPlugin/trunk/config/couchdb/example_map.js
   plugins/sfCouchPlugin/trunk/config/couchdb/example_reduce.js
Removed:
   plugins/sfCouchPlugin/trunk/config/couchdb/all_map.js
Modified:
   plugins/sfCouchPlugin/trunk/README
   plugins/sfCouchPlugin/trunk/lib/sfCouchView.class.php
Log:
reduce example and better readme

Modified: plugins/sfCouchPlugin/trunk/README
===================================================================
--- plugins/sfCouchPlugin/trunk/README  2010-03-17 21:09:27 UTC (rev 28594)
+++ plugins/sfCouchPlugin/trunk/README  2010-03-17 22:43:25 UTC (rev 28595)
@@ -78,10 +78,13 @@
 Views
 -----
 
+[Introduction to 
views](http://wiki.apache.org/CouchDB/Introduction_to_CouchDB_views)
+
 To create a view just put a javascript file in the folder /config/CouchDB
 that is named VIEWNAME_map.js. If you also need a reduce function create 
another
-file named named VIEWNAME_reduce.js. There's a very simple example 
'all_map.js' in
-the distribution.
+file named named VIEWNAME_reduce.js. There's an example view 'alldocs' in the 
+distribution that returns all documents in the db and a map/reduce view called
+'example' that outputs the count of the digits 0-9 in the ids of your 
documents.
 
 Note: In production env the views don't get updated automatically. If you 
change a
 javascript you have to call the task couch:refreshViews.
@@ -89,14 +92,18 @@
     $ php symfony couch:refreshViews
     
 Then call the view with sfCouchView::query($viewName, [$options]). The first 
parameter
-ist the VIEWNAME from the javascript files. The optional second parameter is 
an array 
-with the CouchDB query options [See CouchDB 
wiki](http://wiki.apache.org/CouchDB/Introduction_to_CouchDB_views).
+ist the VIEWNAME from the javascript files. 
 
+    $result = sfCouchView::query('alldocs');
+
+The optional second parameter is an array with the CouchDB query options 
+[See CouchDB 
wiki](http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options).
+
        $options = array('group' => true, 'key' => 'test');
     $result = sfCouchView::query('VIEWNAME', $options);
     
-The result is an sfCouchResponse object. You'll be interested in
-$result->total_rows $result->rows.
+The result is an sfCouchResponse object that holds the returnes arrays. 
+You'll be interested in $result->rows.
 
 
 TODO

Deleted: plugins/sfCouchPlugin/trunk/config/couchdb/all_map.js
===================================================================
--- plugins/sfCouchPlugin/trunk/config/couchdb/all_map.js       2010-03-17 
21:09:27 UTC (rev 28594)
+++ plugins/sfCouchPlugin/trunk/config/couchdb/all_map.js       2010-03-17 
22:43:25 UTC (rev 28595)
@@ -1,3 +0,0 @@
-function(doc) {
-  emit(null, doc);
-}
\ No newline at end of file

Added: plugins/sfCouchPlugin/trunk/config/couchdb/alldocs_map.js
===================================================================
--- plugins/sfCouchPlugin/trunk/config/couchdb/alldocs_map.js                   
        (rev 0)
+++ plugins/sfCouchPlugin/trunk/config/couchdb/alldocs_map.js   2010-03-17 
22:43:25 UTC (rev 28595)
@@ -0,0 +1,3 @@
+function(doc) {
+       emit(null, doc);
+}
\ No newline at end of file


Property changes on: plugins/sfCouchPlugin/trunk/config/couchdb/alldocs_map.js
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: plugins/sfCouchPlugin/trunk/config/couchdb/example_map.js
===================================================================
--- plugins/sfCouchPlugin/trunk/config/couchdb/example_map.js                   
        (rev 0)
+++ plugins/sfCouchPlugin/trunk/config/couchdb/example_map.js   2010-03-17 
22:43:25 UTC (rev 28595)
@@ -0,0 +1,3 @@
+function(doc) {
+  emit(null, doc._id)
+}
\ No newline at end of file


Property changes on: plugins/sfCouchPlugin/trunk/config/couchdb/example_map.js
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: plugins/sfCouchPlugin/trunk/config/couchdb/example_reduce.js
===================================================================
--- plugins/sfCouchPlugin/trunk/config/couchdb/example_reduce.js                
                (rev 0)
+++ plugins/sfCouchPlugin/trunk/config/couchdb/example_reduce.js        
2010-03-17 22:43:25 UTC (rev 28595)
@@ -0,0 +1,30 @@
+// This counts the amount of the numbers 0-9 in the document ids
+// it has no real use, it's just an example that works with every
+// document, regardless of the keys it contains.
+function (keys, values, rereduce) {
+       var counts = {};
+
+       // init the array
+       for (var i=0; i<10; i++) {
+               counts[i] = 0;
+       }
+       
+    // This is the reduce phase, we are reducing over emitted values from
+    // the map functions.
+    for(var i in values) {
+      if (!rereduce) {
+        var chars = values[i].split("");
+      } else {
+        var chars = values[i]; 
+      }
+      for (var j=0; j<chars.length; j++) {
+        if (chars[j] < 10) {
+          counts[chars[j]] = counts[chars[j]]+1;
+        }
+      }
+    };
+
+    // the reduce result. It contains enough information to be rereduced
+    // with other reduce results.
+    return counts;
+};
\ No newline at end of file


Property changes on: 
plugins/sfCouchPlugin/trunk/config/couchdb/example_reduce.js
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: plugins/sfCouchPlugin/trunk/lib/sfCouchView.class.php
===================================================================
--- plugins/sfCouchPlugin/trunk/lib/sfCouchView.class.php       2010-03-17 
21:09:27 UTC (rev 28594)
+++ plugins/sfCouchPlugin/trunk/lib/sfCouchView.class.php       2010-03-17 
22:43:25 UTC (rev 28595)
@@ -18,7 +18,7 @@
      *
      * Validates and transformed paased options to limit the view data, to fit
      * the specifications in the HTTP view API, documented at:
-     * 
http://www.couchdbwiki.com/index.php?title=HTTP_View_API#Querying_Options
+     * http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options
      *
      * @param array $options
      * @return string

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to