Skip to content

Conversation

@marcuscastelo
Copy link
Owner

This PR enhances the food search functionality to address issues where searches for multi-word or diacritic-containing food names (e.g., "Tapioca doce") returned no results. The main changes are:

  • Food search is now diacritic-insensitive, ensuring queries match regardless of accents or special characters.
  • Implements a composed search: first returns exact matches for the full query, then includes partial matches for each word in the query, removing duplicates.
  • Adds a removeDiacritics utility and corresponding tests to support normalization.
  • Updates the repository logic to use the new composed and normalized search.
  • Refactors and tests the search logic for robustness.

No breaking changes.
closes #745

…itics utility

- Normalize diacritics in food search queries and database lookups
- Add shared removeDiacritics utility and tests
- Improves search for names like 'Tapioca doce' regardless of accents
…rtial word matches

- Exact name matches appear first in results
- Partial matches (by any word) appear below, without duplicates
- Improves user experience for multi-word food searches
Copilot AI review requested due to automatic review settings June 12, 2025 09:40
@marcuscastelo marcuscastelo self-assigned this Jun 12, 2025
@vercel
Copy link

vercel bot commented Jun 12, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
marucs-diet ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 12, 2025 9:52am

@github-actions github-actions bot added api API change, bug, or improvement bug Report a problem or malfunction complexity-medium Medium implementation complexity needs-investigation Requires investigation or analysis labels Jun 12, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Enhances food search to handle diacritics and multi-word queries by normalizing input and composing exact and partial matches.

  • Adds a removeDiacritics utility with tests for normalization.
  • Refactors fetchFoodsByName and internalCachedSearchFoods to apply normalization and multi-word logic.
  • Updates prompt file with milestone complexity labeling instructions.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/shared/utils/removeDiacritics.ts Implements diacritic removal utility.
src/shared/utils/removeDiacritics.test.ts Adds unit tests for the diacritic removal function.
src/modules/diet/food/infrastructure/supabaseFoodRepository.ts Normalizes search terms and composes multi-word searches.
.github/prompts/milestone-complexity-labeler.prompt.md Introduces milestone complexity labeling prompt.
Comments suppressed due to low confidence (2)

src/modules/diet/food/infrastructure/supabaseFoodRepository.ts:201

  • Filtering with Array.some inside filter leads to O(n²) behavior. You can use a Set of exact match IDs (e.g., const exactIds = new Set(exactMatches.map(f => f.id))) for O(1) lookups and better performance.
partialMatches = partialResults.flat().filter((food) => !exactMatches.some((f) => f.id === food.id))

src/shared/utils/removeDiacritics.test.ts:6

  • Consider adding tests for edge cases such as strings with multiple diacritics in different scripts or composed characters (e.g., 'Ångström') to ensure full coverage.
it('removes accents from common pt-BR words', () => {

@marcuscastelo marcuscastelo merged commit 9a9d809 into rc/v0.12.0 Jun 12, 2025
7 checks passed
@marcuscastelo marcuscastelo deleted the marcuscastelo/issue745 branch June 12, 2025 09:53
@marcuscastelo marcuscastelo mentioned this pull request Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api API change, bug, or improvement bug Report a problem or malfunction complexity-medium Medium implementation complexity needs-investigation Requires investigation or analysis

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Food search returns Toast but no results for 'Tapioca doce' and others

2 participants