Hi all
I have documents which has a place in both a hierarchy and on a time line.
So I wish to be able to query a view to get all documents (actually their
value), under a node in the hierarchy and between two dates.
A document could look like this:
{
"path": [ "A", "B", "c6", "b9"],
"time": "2010-09-20T23:00:00.000Z",
"value": 117
}
I have come up with this map function, which emits every sub-path from the
root together with the date for each document:
function(doc) {
if (doc.value) {
var d = new Date(Date.parse(doc.time));
var r = [];
var p = [];
r.push(d.getFullYear());
r.push(d.getMonth()+1);
r.push(d.getDate());
r.push(d.getHours());
r.push(d.getMinutes());
r.push(d.getSeconds());
for (var i in doc.path) {
p.push(doc.path[i]);
emit(p.concat(r), doc.value);
};
}
}
//reduce just sums the values
This allows me to do the wanted query
like,
startkey=["A","B","c6",2010,9,20,12,0,0]&endkey=["A","B","c6",2010,9,20,22,0,0,{}]
Is there a better (for some value of better like: faster and/or uses less
space) approach to this problem?
The documents are actually only on the leaves in the hierarchy, but I need
to sum their values up the tree, can this extra information somehow be used
to improve the view?
I can get up to 500.000 of these documents pr. hour. would that be a problem
as I do several emits pr document?
Any tips are welcome.
Best
Søren
--
Søren Hilmer, M.Sc., M.Crypt.
wideTrail Phone: +45 25481225
Pilevænget 41 Email: sh at widetrail.dk <[email protected]>
DK-8961 Allingåbro Web: www.widetrail.dk