Draft
feat: Add key suggestions endpoint for barcode and category tags#320
Conversation
Co-authored-by: teolemon <1689815+teolemon@users.noreply.github.com>
Co-authored-by: teolemon <1689815+teolemon@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Provide 10 key suggestions for category tags
Add key suggestions endpoint for barcode and category tags
Oct 23, 2025
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #320 +/- ##
===========================================
- Coverage 95.06% 79.30% -15.76%
===========================================
Files 5 4 -1
Lines 324 575 +251
===========================================
+ Hits 308 456 +148
- Misses 16 119 +103 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Overview
This PR implements a new endpoint that provides intelligent key suggestions to help users add properties to products in the Open Food Facts Folksonomy Engine. When users are adding key-value pairs to a product, they can now get suggestions based on the most commonly used keys in the database.
What's New
Endpoint:
GET /keys/suggestionsThe new endpoint accepts the following parameters:
barcode(optional): Product barcode to get suggestions forcategory(optional): Category tag (e.g.,en:lasagne) for future category-based filteringowner(optional): Filter by owner (empty for public tags, or user_id for private)limit(optional): Number of suggestions to return (default: 10, max: 100)Note: At least one of
barcodeorcategorymust be provided.Smart Suggestions
The endpoint returns the most commonly used keys from the folksonomy database, intelligently ordered by frequency. When a barcode is provided, it excludes keys that are already present on that product, ensuring suggestions are always relevant and non-redundant.
Example Response:
[ { "k": "color", "count": 15 }, { "k": "size", "count": 12 }, { "k": "material", "count": 8 } ]Example Usage
Implementation Details
KeySuggestionmodel withk(key name) andcount(usage frequency)Testing
Added comprehensive test coverage:
All 41 tests pass (36 existing + 5 new).
Future Enhancements
The implementation includes comments documenting potential future improvements:
This provides a solid foundation that can be extended when external API integration is needed.
Related Issue
Closes #[issue_number] - Provide 10 suggestions of keys for a given Barcode or category tag
Original prompt
Fixes #318
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.