Skip to content

Instantly share code, notes, and snippets.

@FrancisVarga
Created November 22, 2010 16:46
Show Gist options
  • Save FrancisVarga/710227 to your computer and use it in GitHub Desktop.
Save FrancisVarga/710227 to your computer and use it in GitHub Desktop.
couchdb map function for static user view's
function(doc) {
var userID = 500;
var userTags = [
100000036,
100000065,
100000077,
100000046,
100000062,
100000103
];
if(userID != doc.userID)
{
var matchingTags = 0;
for (i in doc.userTags)
{
// Increment matching count for each matching tag
if(userTags.indexOf(doc.userTags[i]) != -1) matchingTags++;
}
if(matchingTags > 0)
{
emit(doc.userID, matchingTags)
}
}
}
function(keys, values, rereduce) {
return sum(values);
}
function(keys, values, rereduce) {
var rv = {};
for (i in values) {
var value = values[i];
for (k in value) {
rv[k] = (rv[k] || 0) + value[k];
}
}
return rv;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment