Files
karaoke-gen/docs/archive/2026-03-08-fuzzy-did-you-mean.plan.md
Andrew Beveridge ☄️andClaude Opus 4.6 93823b8a20 Move song suggestions to Step 2 with fuzzy typo correction (#512)
@coderabbitai ignore

## Summary

- **Simplified Step 1 (Song Info)**: Removed autocomplete — plain text
inputs for artist/title so users aren't confused by autocomplete
behavior
- **Step 2 song suggestions**: Catalog lookup + community version check
fire in parallel with audio search. Results appear as a "Song found in
our database" panel (exact match) or correction suggestion panel while
the user waits
- **Fuzzy "Did you mean?" correction**: When audio search returns poor
results (Tier 3) and catalog has no exact title match, fetches the
artist's discography and fuzzy-matches against the user's title. Shows
amber banner with one-click correction + expandable alternatives list.
Title-based fallback with artist tiebreaker handles garbled artist
fields
- **Visibility step reworked**: Action buttons at top for one-click
select+continue, "change later" note, removed Recommended badge
- **Minor UI polish**: Warning icon on community banner, "Recommended
Audio" heading, YouTube icon on community links, filename above release
in pick card

## Test plan

- [x] 70 new tests added (fuzzy matching, SongInfoStep, AudioSourceStep,
VisibilityStep, CommunityVersionBanner)
- [x] All 677 tests pass
- [x] Manual testing via Playwright: "Fox Stevenson / ruises" typo → Did
you mean Bruises; "fox stevenson bruises / bruises" garbled artist →
correct Fox Stevenson suggestion
- [x] CodeRabbit review completed, issues fixed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 04:40:35 -04:00

2.4 KiB

Plan: Fuzzy "Did you mean?" correction for typos

Created: 2026-03-08 Branch: feat/sess-20260308-0139-step2-song-suggestions Status: Draft

Overview

When a user types a misspelled song title (e.g. "ruises" instead of "Bruises"), the audio search returns poor results (Tier 3 / no lossless) and the catalog search returns nothing. The user has no signal they made a typo. We add a second-pass fuzzy search that triggers when results are poor: fetch the artist's discography from the catalog, fuzzy-match against the user's title, and show a "Did you mean X?" banner. Clicking "Yes" corrects the title and restarts the audio search.

Technical Approach

  1. Trigger condition: Audio search completes with Tier 3 or no results AND catalog search returned 0 results
  2. Fuzzy search: Call api.searchCatalogTracks(artist, artist, 20) — search the artist's name as the query with artist filter to get their top tracks. This is a broader search that doesn't require matching the title.
  3. Client-side fuzzy match: Compare each returned track name against the user's title using simple Levenshtein-like similarity (normalized). Pick the best match above a threshold (e.g. 0.6 similarity).
  4. "Did you mean?" banner: Prominent amber banner with the suggested correction. "Yes, search again" button restarts audio search with corrected artist/title.
  5. Restart flow: Reset search state, update artist/title via parent callback, re-trigger doSearch().

Fuzzy Matching Algorithm

Simple approach — no external dependency needed:

  • Lowercase both strings
  • Calculate longest common subsequence (LCS) ratio: 2 * LCS_length / (len(a) + len(b))
  • Also check if user's title is a substring of the track name or vice versa
  • Threshold: 0.6 for LCS ratio, or substring match with length >= 3
  • Pick the highest-scoring match

Files to Modify

File Action Description
frontend/components/job/steps/AudioSourceStep.tsx Modify Add fuzzy search trigger, "Did you mean?" banner, restart logic

Implementation Steps

  1. Add fuzzyMatch() utility function (inline in AudioSourceStep)
  2. Add state for fuzzy suggestion (fuzzySuggestion, fuzzyDismissed)
  3. Add useEffect that triggers fuzzy search when audio search completes with poor results + no catalog results
  4. Add DidYouMeanBanner component
  5. Add restart handler that clears state and re-runs search with corrected name