incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aurélien Bénel <aurelien.be...@utt.fr>
Subject Re: Help with reduce function
Date Sat, 06 Oct 2012 19:58:34 GMT
> I need the ability to query by date. I don't quite understand what you mean by your last
comment with regards date. Please could you elaborate?

If your view is like this:
["UK", 2011, 10, 6, 20, 30]		null
["UK", 2011, 9, 31, 7, 59]		null
["UK", 2012, 10, 6, 21, 31]		null
["USA", 2011, 9, 1, 12, 00]		null
["USA", 2012, 10, 5, 8, 10]		null
["USA", 2012, 10, 6, 20, 03]	null
["USA", 2012, 10, 6, 21, 31]	null
["USA", 2012, 10, 6, 21, 40]	null

You can query it with group_level=5 and get:
["UK", 2011, 10, 6, 20]		1
["UK", 2011, 9, 31, 7]		1
["UK", 2012, 10, 6, 21]		1
["USA", 2011, 9, 1, 12]		1
["USA", 2012, 10, 5, 8]		1
["USA", 2012, 10, 6, 20]	1
["USA", 2012, 10, 6, 21]	2

with group_level=4:
["UK", 2011, 10, 6]	1
["UK", 2011, 9, 31]	1
["UK", 2012, 10, 6]	1
["USA", 2011, 9, 1]	1
["USA", 2012, 10, 5]	1
["USA", 2012, 10, 6]	3

with group_level=3:
["UK", 2011, 10]	1
["UK", 2011, 9]	1
["UK", 2012, 10]	1
["USA", 2011, 9]	1
["USA", 2012, 10]	4

with group_level=2:
["UK", 2011]		2
["UK", 2012]		1
["USA", 2011]	1
["USA", 2012]	4

with group_level=1:
["UK"]	3
["USA"]	5

So to get all of these stats, you just need to split the date into year, month, hour, minute
when you emit the key.


Regards,

Aurélien


Mime
View raw message