Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leverage levenshtein distance to help users debug easily when there are close matches #582

Open
zikaari opened this issue May 19, 2020 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@zikaari
Copy link

zikaari commented May 19, 2020

Describe the feature you'd like:

Sometimes, due to minor typo or an extra space here and there, a match is not successful and queries throw the error. Due to the typo being non-obvious (like double-space or a dash instead of em-dash etc), it isn't always an instantaneous pin-point to where the problem is.

I think it might be very useful for the users if they see something like this:

Unable to find an element with exact match: 15-25

Found close matches. Did you mean one of these:
  15–25
  19–22

<div>
	<ul> ... </ul>
</div>

Suggested implementation:

When a candidate node is tested for a match, also calculate levenshtein distance from its textContent to the target string, and push the score to an array (along with the node itself). After all nodes are tested, and no match is found, sort the array on distance score and suggest top 3 close candidates to the user.

@kentcdodds
Copy link
Member

I've considered this and think it would be really cool. However, I'm worried that this will be very challenging to do well. I don't have the bandwidth to work on it myself, but I would be willing to look at a pull request for it.

@kentcdodds
Copy link
Member

Note that this doesn't mean it would get merged. So keep that in mind. It would need to not complicate the codebase more than is reasonable.

@zikaari
Copy link
Author

zikaari commented May 19, 2020

I'm worried that this will be very challenging to do well

what challenges do you see off top of your head?

@kentcdodds
Copy link
Member

Just feels like there are dragons lurking. I could be wrong though 😅

@dougbacelar
Copy link

I created a proof of concept to gather some feedback. If there is interest i can finish it up 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants