Add dietary filter to Open Food Facts search#944
Add dietary filter to Open Food Facts search#944stuckvgn wants to merge 4 commits intodavidhealey:masterfrom
Conversation
Uses the ingredients_analysis_tags filter already supported by the OFF API to let users restrict search results to vegan or vegetarian items. Adds a "Dietary Filter" select to Settings > Integration alongside the existing Search Country control. When set to Vegan or Vegetarian the search URL includes the appropriate tagtype parameter; when set to "No filter" (default) behaviour is unchanged.
|
Looks nice. Are there any other filters available, "Gluten Free" for example? |
|
Yes, Gluten Free is definitely available! The Open Food Facts API supports quite a few dietary and allergen-based filters: Dietary/label filters (via
Allergen-free filters (via
Happy to add more filters to this PR if you'd like — just let me know which ones would be most useful for Waistline users. |
|
Closing this PR — on reflection, this change may not be the right fit for this project. Thanks for your time! |
|
Sorry about the accidental close — I still have the answer to your question about additional filters. Reopening. |
|
All those filters seems like they would be useful |
|
Agreed — just pushed an update to this PR that adds all of them:
The vegan/vegetarian filters use the |
Summary
Adds a dietary preference filter to the Open Food Facts search. When enabled in Settings > Integration, search results are filtered to items tagged as vegan or vegetarian in the OFF database.
How it works
The OFF search API already supports filtering on
ingredients_analysis_tagsvia its tag parameter system — the same mechanism used by the existing Search Country filter. This PR adds atagtypeparameter foringredients_analysiswhen a dietary preference is set:tagtype_N=ingredients_analysis&tag_contains_N=contains&tag_N=en:vegantagtype_N=ingredients_analysis&tag_contains_N=contains&tag_N=en:vegetarianThe tag index is set dynamically to avoid colliding with the Search Country
tagtype_0parameter when both filters are active simultaneously.Changes
www/activities/foodlist/js/open-food-facts.js— readsintegration/dietary-filtersetting and appends the tag parameter to search URLswww/activities/settings/views/integration.html— adds a "Dietary Filter" dropdown below the Search Country controlwww/assets/locales/locale-en.json— adds locale strings for the new control; other locales will fall back to the English key until translators add their own