I’m developing a product that helps restaurants serve customers with food allergies - the mission is to hide foods that have certain allergens from search results so that customers cannot see or order those items. To achieve this I originally thought I should label each food item with boolean fields for the type of allergens it contained. So, for example, the 8 ingredients that cause 99% of allergens are Egg, Fish, Milk, Peanut, Shellfish, Soy, Tree nuts, and Wheat so each record would have the following fields:
But there’s a couple problems with this approach:
- Food vendors don’t label foods this way
- It’s time consuming / costly to label it this way since I have over 240,000 food products
- The approach breaks apart if a new allergen needs to be flagged later (since all products would have to be reviewed for the allergen)
So I think the smarter and more flexible way to complete my mission is to use a search engine since:
- My records already contain searchable ingredients, and
- New allergens / unanticipated filtering constraints can be flexibly handled
I’ve already indexed the ~240k records in Algolia where each record has a list of ingredients and I’m able to exclude specific records from a search by using the Advanced search syntax
Now say a user wants to avoid gluten and dairy products:
- How can I structure a search to exclude records that contain gluten… that is, how do I show the records that may contain gluten free but that do not contain gluten, bread, wheat, barley, and rye?
- How can I chain together multiple queries like the one above to filter out multiple allergens, like say gluten AND dairy AND something else?
With advanced querying it is possible to search
vegetarian -gluten (give me vegetarian food without gluten… INCLUSIVE+EXCLUSIVE) or
-gluten (give me any food without gluten… SINGLE EXCLUSIVE)
But it is not possible to search
-gluten -soy -peanut (give me any food without gluten, soy or peanut… MULTIPLE EXCLUSIVE).
As documented here the way to implement a MULTIPLE EXCLUSIVE search is to use faceted search for queries. So, my last question;
- How can I satisfy my first two questions in the event that the user wants a MULTIPLE EXCLUSIVE search? Would faceting still be able to handle this and if so how do I implement that?
If I can figure this out I will become a very happy Algolia customer.
I came across this help page that offers a solution to my problem. Sadly this solution requires that each allergen is already pre-known and labeled within a dedicated
allergen attribute and as I said above, I have over 240k products so labeling each would be costly. Can anyone suggest an alternative solution?