Skip to content

Add token-based matching to improve search recall for non-contiguous package names - #2566

Merged
Simek merged 1 commit into
react-native-community:mainfrom
hryhoriiK97:@hryhoriiK97/improve-search-token-matching
Jun 24, 2026
Merged

Simek merged 1 commit into
react-native-community:mainfrom
hryhoriiK97:@hryhoriiK97/improve-search-token-matching

Conversation

@hryhoriiK97

@hryhoriiK97 hryhoriiK97 commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

📝 Why & how

Improves search recall for libraries whose names contain all the query words but not as a contiguous substring.

Problem: Searching for react-native-markdown would not surface libraries like react-native-enriched-markdown or react-native-live-markdown in the cleanedUpNameMatchPoints, npmPkgNameMatchPoints, and repoNameMatchPoints scoring tiers, because those tiers only checked for contiguous substring matches. The word enriched/live in the middle broke the match entirely, scoring 0.

Solution: After stripping the react-native/react prefix from both the query and package name, split into tokens and check if every token appears in the cleaned-up name. This adds a fallback scoring tier to three match checks:

  • npmPkgNameMatchPoints: 125 (contiguous) → 100 (token match) → 0
  • cleanedUpNameMatchPoints: 100 (contiguous) → 75 (token match) → 0
  • repoNameMatchPoints: 50 (contiguous) → 35 (token match) → 0

Contiguous substring matches still score higher, so a library like react-native-markdown-renderer correctly ranks above react-native-enriched-markdown for the query react-native-markdown — but both now appear in results instead of only the former.

Nagranie.z.ekranu.2026-06-24.o.13.47.14.mov

✅ Checklist

  • Added library to react-native-libraries.json
  • Updated library in react-native-libraries.json
  • Documented how you found or replicated the issue.
  • Explained how you fixed the issue or built the feature.
  • Described how to use or verify the change.

…package names

Co-authored-by: Cursor <cursoragent@cursor.com>

@Simek Simek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Tested the changes locally and it looks like nice improvement, thanks! 🙏

This approach also makes single word queries more accurate which is a nice side-effect. 🙂

@Simek
Simek merged commit 738910c into react-native-community:main Jun 24, 2026
1 check passed
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.

2 participants