I think I found one solution. Using code
from itertools import chain, combinations def all_subsets(ss): return chain(*map(lambda x: combinations(ss, x), range(0, len(ss)+1)))
I can select all possible combinations of ingredients from the lists.
for s in all_subsets(['egg','bread','meat','onion']): if len(s)>2: print s
Gives me the result
("egg", "bread", "meat") ("egg", "bread", "onion") ("egg", "meat", "onion") ("bread", "meat", "onion ") (" egg "," bread "," meat "," onion ")
Now the problem is how to optimize the query so that I can select all recipes containing a list of this ingredient. In MongoDB, I used
receipts.find({'ingredients.name':{'$all':ingredients_list}})
Is there an alternative solution for MySQL?
source share