-
-
Notifications
You must be signed in to change notification settings - Fork 441
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
Feat: Improved module search #3047
base: nextgen
Are you sure you want to change the base?
Conversation
Is there any reason it is still on draft? |
Not anymore. Just wanted to make sure that there weren't any edge cases where it wouldn't work, but is now ready to be merged. |
I see the library you are using is made by you. What distance function did you implement? It doesn't seem to be one I know. |
Well, I chose to write my own library and distance function because I couldn't find any good libraries that did both of the following:
My distance function is slightly inspired by command-score but otherwise created by myself to solve the above-listed problems. |
Hm, basic distance functions are generally considered a solved problem (see Levenshtein distance). Your implementation appears rather inefficient to me. Consider using something like the Wagner-Fischer algorithm for much higher efficiency. |
I ran some tests with the js-levenshtein library and got results where I would prefer the old system (just ranking it depending on if the query existed in the item). Let's take the following example. The user wants to search for 'poison' in a list of words and starts by typing 'poi.' Here, js-levenshtein would recommend the following words as the best for the query 'poi':
Whereas my distance function would recommend these:
Regarding the algorithm's performance, js-levenshtein was about twice as performant as my implementation in my tests. It took Levenshtein about 4364 ms to sort a list of 140 random words 60000 times. It took my implementation 7811 ms to do the same. In the end, this efficiency difference won't be noticeable to the end user because they both are extremely efficient, with mine being able to sort the list of 140 items 7600 times per second. And when testing it in the client i did not feel any speed difference to the old system. If you know any alternatives to Levenshtein that would give better results, I would be happy to take a closer look at them 🙂 |
After trying to further improve the performance of my algorithm, I have managed to bring it down to about 6000 ms to sort the list of 140 words 60000 times. |
@SenkJu Do you still have concerns or could we maybe merge? |
Previously, when searching for the modules and you made a typo, it would not show it. This is now fixed/improved using the typo-safe-search npm package
Examples:
![image](https://private-user-images.githubusercontent.com/85990359/331734018-b69f0a79-3d99-4f57-a34c-d94779b62947.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnV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y1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjE5VDAyMjEzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM3OTM2N2M0N2FjM2Y5N2RkYTNjZjU0NTFlZDMyZTMwZGNhZDNjZWEwY2I1YWZjOTYzOGY3YTM5NmNiNWEwN2MmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Gva_l-dW4mr_hOAeNnmXDy4x19PZ2hfLd7dCj8LNi9Y)
It is still not perfect, but I much prefer this behaviour.