Skip to content

feat: add serving_size and serving_quantity to OFF index schema#412

Open
starkindustries wants to merge 1 commit into
openfoodfacts:mainfrom
starkindustries:add-serving-fields-to-off-schema
Open

feat: add serving_size and serving_quantity to OFF index schema#412
starkindustries wants to merge 1 commit into
openfoodfacts:mainfrom
starkindustries:add-serving-fields-to-off-schema

Conversation

@starkindustries

Copy link
Copy Markdown

The OFF product schema carries per-100g nutriments AND per-serving info (serving_size as a label string, serving_quantity as the parsed gram weight). Per-100g nutriments are already indexed; per-serving siblings are not, so downstream consumers can't surface per-serving info via search-a-licious responses.

This adds both fields to the OFF index config:

  • serving_size: type: text — user-contributed label string ("2 Tbsp (32 g)", "100g", "1 cup (240 ml)")
  • serving_quantity: type: float — parsed grams per serving

Changes

  • data/config/openfoodfacts.yml — two field entries adjacent to nutriments
  • tests/int/data/test_off.yml + tests/unit/data/openfoodfacts_config.yml — matching entries in both test-schema files
  • tests/int/test_search.py — adds serving values to one product in search_sample() and a new test_serving_fields test asserting both fields project through ES into the search response
  • tests/unit/data/test_mapping.json — regenerated via pytest tests/unit/test_indexing.py --update-results

Local validation

  • make test_api_unit → 42/42 pass
  • make test_api_integration → 75 pass, 3 xfailed (vs. 73/3 baseline; +2 is the new test × GET/POST)

Question for reviewers

serving_quantity arrives from the OFF source doc as a string in many products but as a number in others. I picked type: float for parity with the per-100g nutriments. If you'd prefer text for consistency with serving_size, happy to switch.

Note

This is a schema-only addition. Existing OFF indexes won't have the new fields populated until reindexed.

The OFF product schema carries per-100g nutriments AND per-serving info
(`serving_size` as a label string, `serving_quantity` as the parsed gram
weight). Per-100g nutriments are already indexed; per-serving siblings are
not, so downstream consumers can't surface per-serving info via
search-a-licious responses.

This adds both fields to the OFF index config:
- `serving_size`: `type: text` — user-contributed label string
  ("2 Tbsp (32 g)", "100g", "1 cup (240 ml)")
- `serving_quantity`: `type: float` — parsed grams per serving

Changes:
- data/config/openfoodfacts.yml — two field entries adjacent to nutriments
- tests/int/data/test_off.yml + tests/unit/data/openfoodfacts_config.yml
  — matching entries in both test-schema files
- tests/int/test_search.py — adds serving values to one product in
  search_sample() and a new test_serving_fields test asserting both
  fields project through ES into the search response
- tests/unit/data/test_mapping.json — regenerated via
  pytest tests/unit/test_indexing.py --update-results

Local validation:
- make test_api_unit → 42/42 pass
- make test_api_integration → 75 pass, 3 xfailed
  (vs. 73/3 baseline; +2 is the new test × GET/POST)

Question for reviewers: serving_quantity arrives from the OFF source doc
as a string in many products but as a number in others. I picked type:
float for parity with the per-100g nutriments. If you'd prefer text for
consistency with serving_size, happy to switch.

Note: this is a schema-only addition. Existing OFF indexes won't have the
new fields populated until reindexed.
@starkindustries starkindustries force-pushed the add-serving-fields-to-off-schema branch from 9564b19 to a4e8bba Compare May 18, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog (ready for dev)

Development

Successfully merging this pull request may close these issues.

1 participant