unified function for search