You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Cy Scott <cs...@gmail.com> on 2010/03/05 01:28:07 UTC

Views and AND/OR-like Functionality

Just getting started with CouchDB (loving it btw) and am wrapping my brain
around the views. I've seen mention that CouchDB doesn't really handle
ANDing or ORing a la SQL, but is there some way to emulate it?

Here's an example scenario. Say I have documents for different sweaters in
the form of (with _id, _rev, etc.):

{
  "color": "Red", "size": 4, "price": 8.00

}


My data has sweaters of different colors, sizes and prices. The
problem I'm having is when I want to get data for different
permutations like: ALL blue and red sweaters that are size 5 or ANY
green sweaters under $30. I've tried complex keys [doc.color,
doc.size, doc.price] but don't know if this is the right direction.


My simple map function looks like function(doc) { if(doc)
emit([doc.color, doc.size, doc.price], null); };


| key               | value
|----------------------------
|["Blue",  5, 15]  | null
|["Green", 4, 25]  | null
|["Red", 5, 10] | null


Anyone have any thoughts on how to best implement this type of
scenario? Or links to some info, previous thread that might have
covered this. Appreciate any and all help!

Re: Views and AND/OR-like Functionality

Posted by Cy Scott <cs...@gmail.com>.
Great, thanks for the help. Looks like couchdb-lucene is the way to go.

On Thu, Mar 4, 2010 at 5:16 PM, Dmitry Unkovsky <oi...@gmail.com>wrote:

> If your query isn't manageable with 1 complex-key view (like
> ['category','subcategory','type']) then couchdb-lucene [1] is the
> simplest way to go. See here [2] what you can expect of it.
>
> [1] http://github.com/rnewson/couchdb-lucene
> [2] http://lucene.apache.org/java/2_0_0/queryparsersyntax.html
>
> On Fri, Mar 5, 2010 at 2:28 AM, Cy Scott <cs...@gmail.com> wrote:
> > Just getting started with CouchDB (loving it btw) and am wrapping my
> brain
> > around the views. I've seen mention that CouchDB doesn't really handle
> > ANDing or ORing a la SQL, but is there some way to emulate it?
> >
> > Here's an example scenario. Say I have documents for different sweaters
> in
> > the form of (with _id, _rev, etc.):
> >
> > {
> >  "color": "Red", "size": 4, "price": 8.00
> >
> > }
> >
> >
> > My data has sweaters of different colors, sizes and prices. The
> > problem I'm having is when I want to get data for different
> > permutations like: ALL blue and red sweaters that are size 5 or ANY
> > green sweaters under $30. I've tried complex keys [doc.color,
> > doc.size, doc.price] but don't know if this is the right direction.
> >
> >
> > My simple map function looks like function(doc) { if(doc)
> > emit([doc.color, doc.size, doc.price], null); };
> >
> >
> > | key               | value
> > |----------------------------
> > |["Blue",  5, 15]  | null
> > |["Green", 4, 25]  | null
> > |["Red", 5, 10] | null
> >
> >
> > Anyone have any thoughts on how to best implement this type of
> > scenario? Or links to some info, previous thread that might have
> > covered this. Appreciate any and all help!
> >
>
>
>
> --
> DU
>

Re: Views and AND/OR-like Functionality

Posted by Dmitry Unkovsky <oi...@gmail.com>.
If your query isn't manageable with 1 complex-key view (like
['category','subcategory','type']) then couchdb-lucene [1] is the
simplest way to go. See here [2] what you can expect of it.

[1] http://github.com/rnewson/couchdb-lucene
[2] http://lucene.apache.org/java/2_0_0/queryparsersyntax.html

On Fri, Mar 5, 2010 at 2:28 AM, Cy Scott <cs...@gmail.com> wrote:
> Just getting started with CouchDB (loving it btw) and am wrapping my brain
> around the views. I've seen mention that CouchDB doesn't really handle
> ANDing or ORing a la SQL, but is there some way to emulate it?
>
> Here's an example scenario. Say I have documents for different sweaters in
> the form of (with _id, _rev, etc.):
>
> {
>  "color": "Red", "size": 4, "price": 8.00
>
> }
>
>
> My data has sweaters of different colors, sizes and prices. The
> problem I'm having is when I want to get data for different
> permutations like: ALL blue and red sweaters that are size 5 or ANY
> green sweaters under $30. I've tried complex keys [doc.color,
> doc.size, doc.price] but don't know if this is the right direction.
>
>
> My simple map function looks like function(doc) { if(doc)
> emit([doc.color, doc.size, doc.price], null); };
>
>
> | key               | value
> |----------------------------
> |["Blue",  5, 15]  | null
> |["Green", 4, 25]  | null
> |["Red", 5, 10] | null
>
>
> Anyone have any thoughts on how to best implement this type of
> scenario? Or links to some info, previous thread that might have
> covered this. Appreciate any and all help!
>



-- 
DU