Skip to content

Instantly share code, notes, and snippets.

@pulkitsinghal
Last active December 16, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pulkitsinghal/5477903 to your computer and use it in GitHub Desktop.
Save pulkitsinghal/5477903 to your computer and use it in GitHub Desktop.
MAP products bought together in CouchDB and create facets via REDUCE
function(doc) {
if (doc.type === "sale") {
if (doc.register_sale_products && doc.register_sale_products.length>1) {
for (var i=0; i < doc.register_sale_products.length; i++) {
for (var j=0; j < doc.register_sale_products.length; j++) {
if (i != j) {
emit([doc.register_sale_products[i].name,
doc.register_sale_products[j].name],
1)
}}}}}}
function(keys, values) {
return sum(values);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment