Try to extract this out into a reusable method to parse fields and generate a query object