Skip to content

Consolidate fuzzy-scoring into shared core + remove wasted structuredClone (fixes #33)#38

Merged
pablopunk merged 1 commit into
mainfrom
fractal-nvm-work-33-search-ranking-quality-deduplicate-scoring-remove-534843
Jun 11, 2026
Merged

Consolidate fuzzy-scoring into shared core + remove wasted structuredClone (fixes #33)#38
pablopunk merged 1 commit into
mainfrom
fractal-nvm-work-33-search-ranking-quality-deduplicate-scoring-remove-534843

Conversation

@pablopunk

@pablopunk pablopunk commented Jun 11, 2026

Copy link
Copy Markdown
Owner

What

Deduplicates the two copies of the fuzzy-match scoring algorithm into one shared module, and removes a wasted structuredClone from the search hot path.

Changes

  • src/search-ranking.ts (new) — Shared scoreNormalizedNonEmpty(text, query) core (100/80/50/20/0 bands)
  • src/filtering.tsscoreText now a thin wrapper (delegates to core, preserves empty→1)
  • src/electron/search-utils.tsscoreNormalized now a thin wrapper (delegates to core, preserves empty→0, keeps normalize)
  • src/electron/main.ts — Removed discarded structuredClone(sorted) (wasted cycles every keystroke); renamed debug span
  • src/search-ranking.test.ts (new) — 21 tests covering core bands + both wrapper contracts
  • scripts/check-clone-safe-actions.cjs — Updated regex guard for clone removal

Verification

  • pnpm typecheck
  • All 81 frontend tests pass ✅
  • All 35 backend tests pass ✅
  • All 7 check scripts pass ✅
  • palette:debug ranking output unchanged ✅

Closes #33

Summary by CodeRabbit

  • Refactor

    • Consolidated search ranking logic into a shared utility for consistent behavior across the application.
    • Optimized search operations by removing unnecessary deep-cloning overhead.
  • Tests

    • Added comprehensive test coverage for search ranking, including exact matches, fuzzy matching, and edge cases.

…Clone (#33)

- Add src/search-ranking.ts with scoreNormalizedNonEmpty shared core
- Rewrite scoreText in filtering.ts as wrapper (preserves empty→1)
- Rewrite scoreNormalized in search-utils.ts as wrapper (preserves empty→0)
- Remove discarded structuredClone(sorted) from search hot path
- Add src/search-ranking.test.ts with 21 tests (core + both wrappers)
- Update check-clone-safe-actions.cjs for clone removal
- Rename debug span search.sort-prepare-clone → search.sort-prepare
@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nvm Building Building Preview, Comment Jun 11, 2026 11:54am

@pablopunk pablopunk merged commit e343dfb into main Jun 11, 2026
5 of 7 checks passed
@pablopunk pablopunk deleted the fractal-nvm-work-33-search-ranking-quality-deduplicate-scoring-remove-534843 branch June 11, 2026 11:54
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2322ac47-eb1b-4b8e-bbce-44f3c8d4ccf7

📥 Commits

Reviewing files that changed from the base of the PR and between e338f5c and d083346.

📒 Files selected for processing (7)
  • package.json
  • scripts/check-clone-safe-actions.cjs
  • src/electron/main.ts
  • src/electron/search-utils.ts
  • src/filtering.ts
  • src/search-ranking.test.ts
  • src/search-ranking.ts

Walkthrough

This PR consolidates duplicated fuzzy-match scoring logic into a shared module and removes a wasteful structuredClone in the search hot path. A new scoreNormalizedNonEmpty function in src/search-ranking.ts provides the canonical scoring algorithm using numeric bands (exact: 100, prefix: 80, substring: 50, subsequence: 20, no-match: 0). Two existing scorers—scoreText in filtering.ts and scoreNormalized in search-utils.ts—are refactored to delegate their non-empty scoring to this core, removing redundant heuristics. The discarded structuredClone(sorted) in searchActions is deleted and the safety check updated to verify direct return of sorted results. New comprehensive tests validate scoring behavior across all bands and wrapper contracts.

Possibly related PRs

  • pablopunk/nvm#17: Introduces scripts/check-packaged-runtime-imports.cjs validation that this PR's expanded test script likely integrates into the packaged runtime check sequence.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search/ranking quality: deduplicate scoring + remove wasted clone

1 participant