-
Notifications
You must be signed in to change notification settings - Fork 0
/
usergeoindex.js.save
94 lines (93 loc) · 2.78 KB
/
usergeoindex.js.save
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//db.reviewByBusiness.drop();
var mapBusiness = function() {
var values = {
loc: {
type: "Point",
coordinate: [this.latitude, this.longitude]
},
street: this.full_address,
city: this.city,
state: this.state,
name: this.name,
categories: this.categories
};
emit(this.business_id, values);
};
var mapReview = function() {
var values = {
user_id: this.user_id,
review_id: this.review_id,
date: this.date
};
emit(this.business_id, values);
};
var mapTip = function() {
var values = {
user_id: this.user_id,
tip_id: this._id,
date: this.date
};
emit(this.business_id, values);
};
var reducetest = function(k,values) {
return 0;
}
var reduce = function(k, values) {
var result = new Object(),
reviewFields = {
"user_id": '',
"review_id": '',
"tip_id": '',
"date": ''
};
values.forEach(function(value) {
var field;
if ("date" in value) {
if (!("reviews" in result)) {
result.reviews = new Array();
}
result.reviews.push(value);
}
if ("tip_id" in value) {
if (!("tips" in result)) {
result.tips = new Array();
}
result.tips.push(value);
}
if ("reviews" in value) {
if (!("reviews" in result)) {
result.reviews = new Array();
}
value.reviews.forEach(function(v) {
result.reviews.push(v);
//result.reviews.push.apply(result.reviews, value.reviews);
});
}
if ("tips" in value) {
if (!("tips" in result)) {
result.tips = new Array();
}
value.reviews.forEach(function(v) {
result.tips.push(v);
});
}
for (field in value) {
if (value.hasOwnProperty(field) && !(field in reviewFields)) {
result[field] = value[field];
}
}
});
return result;
};
//var finalize = function(k, values) {
// if("reviews" in values) {
// }
// return values;
//}
//db.business.mapReduce(mapBusiness, reduce, {"sort":{"business_id":1}, "out": {"reduce": "reviewByBusiness"}});
//db.review.mapReduce(mapReview, reduce, {"sort":{"business_id":1,"date":1}, "out": {"reduce":"reviewByBusiness"}});
//db.business.mapReduce(mapBusiness, reduce, {"sort":{"business_id":1}, "out": {"reduce":"reviewByBusiness" }});
db.tip.mapReduce(mapTip, reduce, {"sort":{"business_id":1,"date":1}, "out": {"reduce":"reviewByBusiness"}});
db.reviewByBusiness.find().forEach(function(item) {
db.reviewByBusiness.update({_id: item._id}, item.value);
});