i have no idea how the insides of the code looks like, but even with my admittedly rusty programming knowledge can give you an easy solution to the problem:
when you make a meal, save the ingredients in an array, then sort the array [Primary ingredient 1], [Primary Ingredient 2], [Secondary Ingredient 1], [Secondary Ingredient 2]. then sort the two ingredient lists after an index of possible ingredients and store the resulting number in the item.
as an example: Rye is 1, Spelt is 2, Flax is 3, Cranberries are 4, Black Currants are 5, White Currants are 6, Red Currants are 7, Cherries are 8. if i put a meal of Spelt/Spelt/Cranberry/BlackCurrants together, ill get 2245, and if i put a meal of Spelt/Spelt/BlackCurrant/Cranberry together i get 2254. now sort the list to 2245 and you see, BOTH ARE THE SAME
its really not hard, though i dont know how this scales performance-wise. i highly doubt its computing-heavy, since its a one-time operation sorting an array of 4 numbers. Im too long out of the game to judge that though.