Created
November 22, 2010 16:46
-
-
Save FrancisVarga/710227 to your computer and use it in GitHub Desktop.
couchdb map function for static user view's
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(keys, values, rereduce) { | |
return sum(values); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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