fix: Make sure that later matches at the start of words rank higher than earlier substring matches#160
Conversation
…han earlier substring matches
kentcdodds
left a comment
There was a problem hiding this comment.
Thanks for the contribution! I should probably set up prettier in this project eventually, but it's pretty much in maintenance mode anyway as it "does what it says on the tin" so it's hard to justify making investments in it further 😅
Thanks for this improvement!
|
🎉 This PR is included in version 8.0.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
Caution Review failedThe pull request is closed. WalkthroughThe changes introduce a new internal generator to find all occurrences of a substring within a string and update the ranking logic to ensure that Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant getMatchRanking
participant indexesOf
Caller->>getMatchRanking: Call with (testString, stringToRank)
getMatchRanking->>indexesOf: Generate all indices of stringToRank in testString
indexesOf-->>getMatchRanking: Iterator of indices
loop For each index in iterator
getMatchRanking->>getMatchRanking: Check if index is at word start (preceded by space)
alt Word start found
getMatchRanking-->>Caller: Return WORD_STARTS_WITH
end
end
getMatchRanking-->>Caller: Return other ranking (if applicable)
Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes found. Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
What:
Fixes #159, so WORD STARTS WITH matches are returned correctly even if there is an earlier prefix that isn't at the start of a word.
How:
Added a new generator to call indexOf multiple times (to avoid needing to iterate through the whole string). I'm open to suggestion that this might be over-complicating it (as opposed
if (testString.includes(` ${stringToRank}`))) but it at least keeps the search consistent.Checklist:
Summary by CodeRabbit
Refactor
Bug Fixes
Style