Skip to content

Add dietary filter to Open Food Facts search#944

Open
stuckvgn wants to merge 4 commits intodavidhealey:masterfrom
stuckvgn:add-off-dietary-filter
Open

Add dietary filter to Open Food Facts search#944
stuckvgn wants to merge 4 commits intodavidhealey:masterfrom
stuckvgn:add-off-dietary-filter

Conversation

@stuckvgn
Copy link
Copy Markdown

@stuckvgn stuckvgn commented Mar 1, 2026

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_tags via its tag parameter system — the same mechanism used by the existing Search Country filter. This PR adds a tagtype parameter for ingredients_analysis when a dietary preference is set:

  • Vegantagtype_N=ingredients_analysis&tag_contains_N=contains&tag_N=en:vegan
  • Vegetariantagtype_N=ingredients_analysis&tag_contains_N=contains&tag_N=en:vegetarian
  • No filter (default) → no change to the existing request

The tag index is set dynamically to avoid colliding with the Search Country tagtype_0 parameter when both filters are active simultaneously.

Changes

  • www/activities/foodlist/js/open-food-facts.js — reads integration/dietary-filter setting and appends the tag parameter to search URLs
  • www/activities/settings/views/integration.html — adds a "Dietary Filter" dropdown below the Search Country control
  • www/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

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.
@davidhealey
Copy link
Copy Markdown
Owner

Looks nice. Are there any other filters available, "Gluten Free" for example?

@stuckvgn
Copy link
Copy Markdown
Author

Yes, Gluten Free is definitely available! The Open Food Facts API supports quite a few dietary and allergen-based filters:

Dietary/label filters (via labels_tags):

  • en:gluten-free
  • en:vegan
  • en:vegetarian
  • en:palm-oil-free
  • en:organic

Allergen-free filters (via allergens_tags):

  • en:gluten, en:milk, en:eggs, en:nuts, en:soy, en:fish, en:shellfish, and more

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.

@stuckvgn
Copy link
Copy Markdown
Author

Closing this PR — on reflection, this change may not be the right fit for this project. Thanks for your time!

@stuckvgn stuckvgn closed this Mar 14, 2026
@stuckvgn
Copy link
Copy Markdown
Author

Sorry about the accidental close — I still have the answer to your question about additional filters. Reopening.

@stuckvgn stuckvgn reopened this Mar 14, 2026
@davidhealey
Copy link
Copy Markdown
Owner

All those filters seems like they would be useful

@stuckvgn
Copy link
Copy Markdown
Author

Agreed — just pushed an update to this PR that adds all of them:

  • Gluten Free (via labels_tags: en:gluten-free)
  • Palm Oil Free (via labels_tags: en:palm-oil-free)
  • Organic (via labels_tags: en:organic)

The vegan/vegetarian filters use the ingredients_analysis tagtype; the new label-based filters use the labels tagtype — the logic picks the right one automatically based on the selection. Let me know if you'd like any others added or anything adjusted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants