You can fake it if you want: function(doc) { if(doc.type == "Article" && (doc.location == "NY" || doc.location == "CA" )){ emit(["NYCA", doc.release_date], doc) } }
Or join the discussion about why views should have search fields so this could be resolved once and for all. They it would be: function(doc) { if(doc.type == "Article" )){ emit(doc.release_date, doc, doc.location) } } then query it with: _view/articles?limit=5&decending=true&search="NY OR CA" Btw you only need this to call it from couchapp. It's better not to have the whole url so you can easily change hosts and even database names like application-test. There is some work going on in this direction and it's important to let people know that this is important. Regards, Olafur Arason On Fri, Apr 8, 2011 at 03:13, Pierre-Alexandre Lacerte <pierrealexandre.lace...@gmail.com> wrote: > I am currently trying to create a view to reproduce this SQL query: > > SELECT * FROM articles WHERE articles.location="NY" OR articles.location="CA" > ORDER BY articles.release_date DESC > > I tried to create a view with a complex key: function(doc) { if(doc.type == > "Article") { emit([doc.location, doc.release_date], doc) } } > > And then using startkey and endkey to retrieve one location and ordering the > result on the release date. > > http://myhost.com:8000/mydb/_design/application/_view/articles?startkey=["NY", > {}]&endkey=["NY"]&limit=5&descending=true > > This works fine. > > However, I learned that I cannot send multiple startkeys and endkeys to my > view. (To mimic WHERE articles.location="NY" OR articles.location="CA") > > How should I design this? (It could happen that I would need to query for 15 > different locations) > > So far, I have 3 suggestions: > 1- Store the view output in its own database, and make a new view to sort by > release date. I'm not sure if this option will be fast and scale well... > 2- Use couchdb-lucene. > 3- Hack my version to support multiple startkeys or endkeys. > https://issues.apache.org/jira/browse/COUCHDB-523 > > Thanks for your help, > > Pierre