feat: add serving_size and serving_quantity to OFF index schema#412
Open
starkindustries wants to merge 1 commit into
Open
feat: add serving_size and serving_quantity to OFF index schema#412starkindustries wants to merge 1 commit into
starkindustries wants to merge 1 commit into
Conversation
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.
9564b19 to
a4e8bba
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The OFF product schema carries per-100g nutriments AND per-serving info (
serving_sizeas a label string,serving_quantityas 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 servingChanges
data/config/openfoodfacts.yml— two field entries adjacent tonutrimentstests/int/data/test_off.yml+tests/unit/data/openfoodfacts_config.yml— matching entries in both test-schema filestests/int/test_search.py— adds serving values to one product insearch_sample()and a newtest_serving_fieldstest asserting both fields project through ES into the search responsetests/unit/data/test_mapping.json— regenerated viapytest tests/unit/test_indexing.py --update-resultsLocal validation
make test_api_unit→ 42/42 passmake test_api_integration→ 75 pass, 3 xfailed (vs. 73/3 baseline; +2 is the new test × GET/POST)Question for reviewers
serving_quantityarrives from the OFF source doc as a string in many products but as a number in others. I pickedtype: floatfor parity with the per-100g nutriments. If you'd prefertextfor consistency withserving_size, happy to switch.Note
This is a schema-only addition. Existing OFF indexes won't have the new fields populated until reindexed.