Fix DB queries for search