One would think this would be easy, but the problem is that even with a definitive statement of exactly what you want, ie, like you just provided, there still are many, many ambiguities.
For example, here's one of my own photos. Would you classify "the primary hue" of this photo as blue or orange/red?
Some of the best photos have strong color contrasts like this and are quite common. For example, it took me only seconds to find this example.
I think that examples like this illustrates why, if you Google keywords like {sort photos by color}, one finds that very few people (other than Picasa) have attempted to provide an automated way to do so. In fact, even Picasa's tool is not really a "sort by color" tool, but rather a "search for color" tool. Although it may sound like I may be parsing words, it turns out that it is easier to write an algorithm that simply looks for whether or not a particular hue occupies a significant fraction of all the pixels in a photo compared to attempting to say if one picture is "more red" than another and then putting the results in order.
Sorry I couldn't be more encouraging.
Cheers,
Tom M