Fix search results sorting bugs in database classes.