incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <paul.joseph.da...@gmail.com>
Subject Re: multiple key word count query problem
Date Mon, 20 Jul 2009 02:16:00 GMT
On Sun, Jul 19, 2009 at 9:14 PM, Tommy Chheng<tommy.chheng@gmail.com> wrote:
> I have a simple word count view defined as:
> --------
> function(doc) {
>  if(doc['couchrest-type'] == 'NsfGrant'){
>    var words = doc['abstract'].split(/\W+/);
>    words.forEach(function(word){
>      if (word.length > 1) emit([word, doc['_id']],1);
>    });
>  }
> }
>
> function(keys, values, rereduce) {
>  return sum(values);
> }
> --------
> where the key's first parameter is the word and the 2nd parameter is the
> document_id.
>
> so i can do a query like this to get all the documents with the word "the"
> correctly.
> http://localhost:5984/nsf_grants/_design/NsfGrant/_view/by_word_doc_count?startkey=["the"]&endkey=["the",{}]&group_level=2
>
> I'm having trouble doing queries on the 2nd parameter, how can i find all
> the words in a particular document?
> I tried
> http://localhost:5984/nsf_grants/_design/NsfGrant/_view/by_word_doc_count?key=[null,"0808605"]&group_level=2
> which gives nothing(thinking that null would match all words)
> and
> http://localhost:5984/nsf_grants/_design/NsfGrant/_view/by_word_doc_count?startkey=[null,"0808605"]&endkey=[{},"0808605"]&group_level=2
> which gives all results. Why is this?
>
> Thanks,
> Tommy
>

Querying a view is asking for a slice of a sorted list. Start and end
keys delimit the range of rows returned. The solution to your problem
is to create a second view so you can query by docid.

Paul Davis

Mime
View raw message