fix search with empty result set or invalid custom query
add test for search with empty result