couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Hinrichs - DM&T" <dunde...@gmail.com>
Subject Re: RE: How to create view to count number of unique values from documents .... ?
Date Fri, 16 Jan 2009 14:32:07 GMT
On Fri, Jan 16, 2009 at 5:34 AM, Seledkin Vyacheslav <
viacheslav.seledkin@avicomp.com> wrote:

>
> Thanks for reply, Chris but you gave me no ansver. Please read my question
> carefully. I don't want to find how many times any particular tag are
> encountered across the documents, but how many unique tags are in documents.
> The documented example only gives me ability to request and count the
> number of rows in ansver on the client, it is not acceptable because of huge
> amount of data.
>
> > The documented example is the way to do it.  It's really slow to
> > generate the view the first time, but as you add documents it will
> > only need to regenerate the index for those new documents.
>
> > Chris
>
> >> On Thu, Jan 15, 2009 at 2:56 AM, Viacheslav Seledkin
> >> After reading all docs I think it is not trivial. The task itself: I
> have
> >> documents with fields
> >> ..............
> >> doc(N) = {
> >> ...
> >> tag:"y",
> >> tag:"o",
> >> tag:"b",
> >> tag:"b",
> >> tag:"v",
> >> tag:"r",
> >> ............
> >> }
> >>
> >> doc(N+1) = {
> >> ...
> >> tag:"a",
> >> tag:"b",
> >> tag:"t",
> >> tag:"b",
> >> tag:"u",
> >> tag:"r",
> >> ...
> >> }
> >>
> >> doc(N+2)= {
> >> ...
> >> tag:"t",
> >> tag:"m",
> >> tag:"i",
> >> tag:"b",
> >> tag:"l",
> >> tag:"z",
> >> ...........
> >> }
> >> .............
> >> and so on...
> >>
> >> How to create a view that allows to get number of unique tags throught
> >> various range of some keys.
> >> i.e
> >> ..
> >> emit(keyN1,"y") - from document doc(N)
> >> emit(keyN2,"o") - from document doc(N)
> >> ....
> >> emit(key(N+2),"z") - from document doc(N+2)
> >> ..
> >>
> >> and view request
> >> http://.../_view/?startkey=someStartKey&endkey=someEndKey
> >> gives me something like
> >>
> >> {"rows":[{"key":null,"value":12}]}????
> >>
> >> Of course i can use documented example with emit("y",1) and
> >> reduce()(return
> >> sum(values);) and count the number of rows returned to the client but i
> >> have
> >> many thousands of tags and it is not effective. Any help appreciated.
> >>
> >>
>
If I'm understanding, you will need to do an initial reduction in the
primary map function.
assuming your tags are in a list structure in the doc...

for (var t in doc.tags){
  // create associative array (tagcnt) keyed on tag, incrementing count
}
//emit values from tagcnt  here
for (t in tagcnt){
  emit( ...stuff... )
}

Regards,
Jeff

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