Improve search function to get total number