incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From umut utkan <umut.ut...@gmail.com>
Subject Re: Question about views
Date Tue, 28 Apr 2009 12:39:56 GMT
Thanks Brian,

Now I got the idea about the startkey and the endkey parameters.
I can use prefixes, actually it is not very clear in the documentation.

Thanks to everybody.

Umut

On Tue, Apr 28, 2009 at 3:27 PM, Brian Candler <B.Candler@pobox.com> wrote:

> 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.
>



-- 
Umut UTKAN
http://www.hoydaa.org
http://snippets.hoydaa.org
http://www.googlevolume.com

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message