Add conservative typo-tolerant fuzzy matching to catalogue searches - #1800
Conversation
This pull request has been ignored for the connected project Preview Branches by Supabase. |
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdded conservative typo matching with bounded Damerau-Levenshtein distance. Integrated fuzzy fallback scoring into catalogue, therapy, formulation, specifier, and factsheet searches. Added regression tests for supported and rejected matches. ChangesFuzzy search behavior
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant SearchEntry
participant fuzzySearchTokenCount
participant SearchRecord
participant SearchResult
SearchEntry->>SearchRecord: evaluate literal query matches
SearchEntry->>fuzzySearchTokenCount: evaluate fuzzy tokens when literal score is zero
fuzzySearchTokenCount-->>SearchEntry: return fuzzy match count
SearchEntry->>SearchResult: include and rank matching records
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/lib/catalog-search.ts`:
- Around line 27-30: Update typoDistanceLimit so four-character terms receive no
fuzzy-matching allowance, requiring at least five characters before returning a
nonzero distance. Preserve the existing thresholds for terms of length eight or
more and add a regression asserting fuzzySearchTokenCount("SSRI", "SNRI")
returns 0.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a9e629da-060f-4d98-9353-a01fc6b9239b
📒 Files selected for processing (12)
docs/branch-review-ledger.mdsrc/components/factsheets/factsheets-data.tssrc/components/therapy-compass/data/select.tssrc/lib/catalog-search.tssrc/lib/formulation.tssrc/lib/specifiers.tssrc/lib/therapies.tstests/catalog-search.test.tstests/factsheets-data.test.tstests/formulation.test.tstests/specifiers.test.tstests/therapy-card-preview.test.ts
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:a553d65c49
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Sync stale PR head; merge-tree was clean (GitHub DIRTY was behind-main only).
There was a problem hiding this comment.
Pull request overview
This PR adds conservative, typo-tolerant fuzzy matching to non-answer catalogue-style searches (therapies, formulation mechanisms, specifiers, factsheets, and shared catalogue ranker) while keeping answer/RAG behavior unchanged.
Changes:
- Introduces a bounded Damerau–Levenshtein helper (
fuzzySearchTokenCount) and integrates it as a fallback signal inrankCatalogRecords. - Applies fuzzy fallback to several catalogue consumers (therapy compass search, server-side therapy catalogue, specifiers, formulation mechanisms, factsheets filtering).
- Adds focused regression tests covering common misspellings, insertions/omissions, and transpositions.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/therapy-card-preview.test.ts | Adds a regression test ensuring therapy search recovers a close typo. |
| tests/specifiers.test.ts | Adds a regression test for typo recovery in specifier search. |
| tests/formulation.test.ts | Adds a regression test for typo recovery in mechanism search. |
| tests/factsheets-data.test.ts | Adds a regression test for typo recovery in factsheets filtering. |
| tests/catalog-search.test.ts | Adds tests for fuzzy token counting + guardrails (short abbreviations, unrelated words). |
| src/lib/therapies.ts | Adds fuzzy fallback to server-side therapy record search scoring. |
| src/lib/specifiers.ts | Adds fuzzy fallback to specifier scoring when literal score is absent. |
| src/lib/formulation.ts | Adds fuzzy fallback to mechanism scoring when literal score is absent. |
| src/lib/catalog-search.ts | Adds bounded typo-distance logic and fuzzy evidence integration/signals in shared ranker. |
| src/components/therapy-compass/data/select.ts | Adds fuzzy fallback to therapy compass UI-side scoring when literal matches are absent. |
| src/components/factsheets/factsheets-data.ts | Adds fuzzy fallback to factsheets search-page filter logic. |
| docs/branch-review-ledger.md | Appends a ledger row related to this work. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
SSRI and SNRI are one Damerau-Levenshtein edit apart; raise the fuzzy floor to five characters and pin a regression so medication-class labels do not cross-match in catalogue fallback consumers.
Babysit / unblock progress
Merge left until PR policy unblocked. |
Cloud agent tokens cannot PATCH pull request bodies; the Sync PR policy body job applies this scratch template with pull-requests:write. Remove before merge so it does not land on main (#230).
Keeps the scratch template off the merge tip (#230) and retriggers PR policy against the already-synced Clinical Governance Preflight body.
CI triageCI failed on this PR. Automated classification of the 2 failed job(s):
Compared with main CI run #9614 (cancelled). Classification is evidence routing, not permission to ignore a failure. Exact quarantined Playwright identities remain governed by the flake ledger. |
Production UI shard 1 failed locator.check({ force }) on the controlled
sr-only CBT cycle radio. Click the visible label instead.BigSimmo
commented
Aug 10, 2026
Unblock snapshot (2026-08-10): PR head is b680dee. Current state is merge-tree clean, mergeable=true, mergeStateStatus=BEHIND, required workflows passing (Gitleaks + PR policy + PR required). I found 1 unresolved review thread on src/lib/catalog-search.ts (line 198) from copilot about fuzzy-signal ordering. I agree this is a valid behavior concern but it is currently advisory only, not a required-check blocker; no code change made during unblock pass. Mergeable blockers remain clear; merge left to you, with follow-up fix noted. |
Uh oh!
There was an error while loading. Please reload this page.
Four merge-safe intake requests, no canonical ledger edit: - P1 rec: no gate detects a merged PR whose content is silently reverted by a later merge resolution. Blob sweep over origin/main found seven such PRs since 2026-08-06, six first wiped at one commit in the PR #1815 unblock chain. The reverts took each PR's tests in the same stroke, which is why nothing went red. - P2 task: re-land PR #1800 (fuzzy catalogue search) with the #310 one-edit cap applied in the same commit. - P2 task: re-land PR #1803 (--shadow-tight retirement); 67 files on main still reference the retired alias. - update #310: re-scoped. The defect is not reachable on main because the matcher is absent, not because it was fixed, so the row must not be closed and the fix belongs in the #1800 re-land. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DuYJz8hauCsCdx8r4fXiZU
Summary
Verification
node scripts/run-vitest.mjs run tests/catalog-search.test.ts tests/specifiers.test.ts tests/formulation.test.ts tests/factsheets-data.test.ts tests/therapy-card-preview.test.ts --reporter=dot— 49 passednpm run typecheckand changed-file ESLint checks passed for the edited filesnpm run formatcompleted cleanlynpm run verify:pr-localfull gate deferred to hosted CI after branch syncRisk and rollout
Clinical Governance Preflight
Clinical KB Database(sjrfecxgysukkwxsowpy)Notes
origin/main(merge-tree was clean; GitHub DIRTY was staleness) and raised the fuzzy floor to five characters for the SSRI/SNRI CodeRabbit finding.Summary by CodeRabbit