couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Frederik Fix <>
Subject [Patch] striped queries/faceted search
Date Tue, 10 Feb 2009 10:54:05 GMT
Hi all,

for the project I'm working on right now, I needed the ability to run  
a reduce over non-continuous ranges along the index. In order to  
achieve this I have implemented striped queries, where you can specify  
multiple startkey/endkey ranges in a single request. As a nice side  
effect this allows faceted search (for discrete keys). Heres an example:

Say I have the following map function:

function() {
    emit([doc.rooms, doc.price], doc);

where doc.rooms and doc.price are both integers. Now lets say i want  
to find every document with a number of rooms between 2 and 4 and a  
price between 100 and 1000. I can then do the following query:

db.view("my_view",{},{stripes: [{startkey: [2, 100], endkey: [2,  
1000]}, {startkey: [3, 100], endkey: [3, 1000]}, {startkey: [4, 100],  
endkey: [4, 1000]}]});

If the view included a reduce function that would work too.

As you can probably see this patch introduced a change to the JS API  
(but not the HTTP). The keys parameter is now a hash which can either  
take a keys param or a stripes. The keys param works as before. The  
stripes param takes an array of hashes each having a startkey, endkey  

The state of the patch is still somewhat raw, with no error checking  
on the stripes part of the API. Furthermore it might be useful to  
extend the limit, skip and descending options to the stripes.

The patch is against the current trunk version (rev 742925) and all  
tests pass.

I'd appreciate some feedback on the implementation and maybe some info  
on how to proceed in integrating this into CouchDB.


View raw message