(The title for this question isn't the best, but I'm unsure how else to word it!)
I'm working on a search form which contains a checklist of values. Basically, a checked item means 'include this type in the search'. Something like this:
Search for item: __________
Search in:
[ ] Fresh Foods
[ ] Frozen Foods
[ ] Beverages
[ ] Deli Counter
I have an object to represent this search:
class FoodSearchCriteria{
public string SearchString {get;set;}
public bool SearchFreshFoods {get;set;}
public bool SearchFrozenFoods {get;set;}
public bool SearchBeverages {get;set;}
public bool SearchDeliCounter {get;set;}
}
The only way I can think of doing this atm is like this:
public IList<FoodItem> FindFoodItems(FoodSearchCriteria criteria)
// in reality, this is a fuzzy search not an exact match
var matches = _DB.FoodItems.Where(x => x.FoodTitle == SearchString);
var inCategories = new List<FoodItem>();
if (criteria.SearchFreshFoods)
inCategories.Add(matches.Where(x => x.Type == 'Fresh Foods'));
if (criteria.SearchFrozenFoods)
inCategories.Add(matches.Where(x => x.Type == 'Frozen Foods'));
//etc etc
return inCategories;
}
This feels like a code smell to me, what would be a better way to approach it?