Added compare method for sort in search method