I am new to Couchdb and currently I hv been stuck on a small(probably...) problem on using couchdb map-reduce function and since I can not find any relevant infos online. I hv to ask help for myself here.
Basically the scenario is like this: I am using a map function to count the times of a certain word that appears in a certain doc. And do the emit simply like:
emit(word,1)
In this way, If I need to get the sum value of each word so that to figure out how many times each word appears in all the docs. I could simply code the reduce function like:
function(key, values, rereduce)
{
return sum(values);
}
But my real need is to only return sum(values) that large than 3000 (to find out word that appears more than 3000 times in all the docs). So I try to do like this:
function(key, values, rereduce)
{
if(sum(values)>3000)
return sum(values);
}
But in this way, all the words that appears less than 3000 times would still be returned but with a value of null. I know this is because reduce function must return something thus when the 'if' statement did not match, it has to return null instead. But is there anyone who could give me useful suggestion on this -- how to return sum(values) that meets certain conditions only...