incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Candler <B.Cand...@pobox.com>
Subject Re: Question about views
Date Tue, 28 Apr 2009 12:27:50 GMT
On Tue, Apr 28, 2009 at 09:04:18AM +0300, umut utkan wrote:
> Hi All,
> 
> I am trying to create a view that can return documents according to
> a virtual hierarchy --which is stored as an attribute in the document
> like hierarchy: "products/motorcycle/dual-purpose". Is it possible to
> pass parameters to this view so that it can be used inside map/reduce
> functions? Otherwise i am going to end up with numerous views.

Not sure exactly what you want. Remember that:

(1) You can search on key prefixes. So

  startkey="products/motorcycle/"&endkey="products/motorcycle/ZZZZZZZZ"

finds everything under that part of the hierarchy.

(2) you can emit multiple key/value pairs from the same document. e.g.
(untested)

//MAP
function(doc) {
  if (doc.hierarchy) {
    var k = doc.hierarchy.split('/');
    for (var i in k) { emit(k[i], null); }
  }
}

You could search this view using key="motorcycle" to get anything which has
motorcycle anywhere along the path, or
startkey="motor"&endkey="motorZZZZZZZZ"

(3) Values don't need to be strings, so you could store an already-split
array like ["products","motorcycle","dual-purpose"] if you prefer

(4) There are some more ideas at
http://wiki.apache.org/couchdb/How_to_store_hierarchical_data

HTH,

Brian.

Mime
View raw message