migrates the search logic from view to model