Refactor Purchase into ActiveRecord
Refactor search method to use ActiveRecord scope.