We have a situation where we are doing a search, and a user can provide a list of items as a filter for the search.
For example, let's say we were searching for recipes that had particular foods in them. We might have a list of possible foods, like:
- beef
- chicken
- fish
- carrots
- peas
- onions
- rice
- beans
But we also want the user to be able to search for "any meat" or "any vegetable" and have it return anything that matches all the meat possibilities or all the vegetable possibilities.
We could just have the client do the parsing and when the user selects "meat", send all the meat choices. But there is other logic we need to do when the user selects a higher category like that. For example, if they select "any meat", we can search an additional database that has recipes that are flagged "meat", not by the individual meats.
(I'm making up this example, based on our actual business requirements which are far more boring, but this is essentially the idea.)
There are a couple of possible solutions I can think of, which are shades of the same thing:
- Have two different lists in the search criteria, one for an enum of individual items and one for an enum of groups, then combine the two when filtering searches.
- Have a single list in the search criteria with an enum that includes both individual items and group items.
But I feel like I'm missing a solution that might be a little more elegant in representing the group/individual relationship. Is there a pattern that addresses this situation?
(PS: This is in Java, but I don't think that particularly matters.)
Aucun commentaire:
Enregistrer un commentaire