On Sun, Jul 05, 2009 at 03:18:33PM -0500, Ross Bates wrote:
> Hi Paul - thank you for the pointers. Something I'm unclear on though...
> using a sum in the reduce returns something like this for all the tags:
>
> foo, 3
> bar, 5
> baz, 7
>
> When I use the multi-key fetch against the view it doesn't return specific
> docid's for each tag, just a subset of tags and their counts.
>
> POST {"keys": ["foo", "bar"]}
>
> foo, 3
> bar, 5
>
> How can I get access to the list of docid's which make up the total?
You query the view again with reduce=false, which turns it back into a
regular map view.
The idea is you'd query in this case only for key "foo", because this
returns the smallest number of documents, and then filter the result set
client-side to documents which also include key "bar".
You can read the view using include_docs=true to get the whole docs, or in
your view you can emit the parts of doc you're interested in as the value.
Your original code was:
function(doc) {
for(i in doc.tags) {
emit(doc.tags[i], doc._id);
}
}
Note that emitting doc._id is not useful (every K/V pair also emits the id
as well), so you could have
// Query with include_docs=true
function(doc) {
for(i in doc.tags) {
emit(doc.tags[i], null);
}
}
Or:
// Index is bigger but faster to read
function(doc) {
for(i in doc.tags) {
emit(doc.tags[i], doc);
}
}
Or:
// Just emit the pieces you need when processing the view
function(doc) {
for(i in doc.tags) {
emit(doc.tags[i], {tags: doc.tags});
}
}