Handle query with grace

If a query is given, we search for any closely matching image. We then
return a random image from the resulting match list. If no matches are
found, we return a random image.