Hi all,

This has been bugging me for a while now. I don't understand how view collation is supposed to work when there's an array of startkeys and endkeys. I've been working around it, but thought "time to ask the list".

Say we have a list of Artists:

{
   "name": "Spice Girls",
   "country": "UK",
   "type": "artist",
   "genre": "Pop",
}

{
   "name": "Hannah Montana",
   "country": "USA",
   "type": "artist",
   "genre": "Pop",
}

{
   "name": "Def Leppard",
   "country": "USA",
   "type": "artist",
   "genre": "Rock",
}

We then make a basic view to find by genre and country:

function(doc) {
  if (doc.type == 'artist' )
    emit([doc.genre, doc.country], doc.name);
    }

Now let's test:

>> Artist.find_by_genre_country :country => "USA", :genre => "Rock"
key array: [["Rock", "USA"], ["Rock", "USA"]]
=> ["Def Leppard"]

Awesome. What's the best pop act in Britain?

>> Artist.find_by_genre_country :country => "UK", :genre => "Pop"
key array: [["Pop", "UK"], ["Pop", "UK"]]
=> ["Spice Girls"]

Thought so. How about all worthwhile Pop acts?

>> Artist.find_by_genre_country :genre => "Pop"
key array: [["Pop", nil], ["Pop", {}]]
=> ["Spice Girls", "Hannah Montana"]

There you have it. Filtering on the left side works. How about all artists in the USA?

>> Artist.find_by_genre_country :country => "USA"
key array: [[nil, "USA"], [{}, "USA"]]
=> ["Spice Girls", "Hannah Montana", "Def Leppard"]

Huh?

What am I missing here? Am I doing something wrong, or is "filtering" only available left-to-right? Does it stop when it hits a "wildcard" like the NULL/{} trick?

I actually have worked around it, but have been wondering about this for a long time. Sorry if it's a really stupid question and I have missed something incredibly obvious...

thanks a lot.

Sho

Reply via email to