Speed up queries for search and browse, fix empty query bug.