On May 4, 2009, at 5:15 PM, Chris Anderson wrote:
On Mon, May 4, 2009 at 2:00 PM, Brian Candler <[email protected]>
wrote:
Just a quick check to see if someone has a view strategy I can
borrow.
Suppose I have a large collection of documents each of which
contains a
range like this:
lower: <value1>,
upper: <value2>
I want to be able to search these documents, such that when given a
value v,
I quickly find all documents where v lies between the lower and upper
values. Any suggestions?
The simplest approach is to define a granularity for your queries and
then emit each value within the range at that granularity from each
document.
This is probably the best option given the way CouchDB views work.
On the map phase, round down the start key and end key down to the
level of granularity, and emit each a key for each interval of
granularity until you reach the end.
On lookup, the client then rounds the input start key and end key down
and does a range query. It then filters the results client side,
removing results that fall within the rounded ranges but don't
actually fall within the input key ranges. I think this could be done
by the _list functionality.
This method allows for fully continuous range queries, but the
tradeoff is more key/value emits versus the extra work of filtering
out the out of range results at query time.
-Damien