factor out search api