refactoring of get_count_for_search()