-
Notifications
You must be signed in to change notification settings - Fork 4k
Add fuzzy search to selectbox #2933
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
Conversation
kmcgrady
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good. Any test we can add for this?
| let arr = _(options) | ||
|
|
||
| // keep the options that fuzzy-match our pattern | ||
| arr = arr.filter((opt: SelectOption) => fzy.hasMatch(pattern, opt.label)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can this go in the if (pattern) block below too?
| // if the user provided a pattern, sort by score, highest first; otherwise, | ||
| // retain original order (scoring based on empty pattern makes no sense) | ||
| if (pattern) { | ||
| arr = arr.sortBy((opt: SelectOption) => fzy.score(pattern, opt.label)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: No strong opinion on this, but it might be cleaner to just chain the lodash calls without reassigning arr.
Something like
if (!pattern) {
return options
}
return _(options)
.filter(...)
.sortBy(...)
.reverse()
.values()is equivalent and avoids variable reassignment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had this at first, but the .sortBy() and .reverse() are conditional on pattern, and I don't know how to add a conditional into a chain.
I could chain the sortBy and reverse() together though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, saw your comment above about putting the .filter() in the if too. That cleans things up.
* develop: Set baseUrl to . Speed up CircleCI more (#3025) Add events to keep track of theme changes and other theme stats (#3012) Have MetricsManager enqueue events when disconnected (#3011) Fix for query param issue with base url (#2894) Add fuzzy search to selectbox (#2933) Informative repr methods for our python classes (#3027) ComponentInstance: handle iframe changes (#3015)
* st_form: Set baseUrl to . Speed up CircleCI more (streamlit#3025) Add events to keep track of theme changes and other theme stats (streamlit#3012) Have MetricsManager enqueue events when disconnected (streamlit#3011) Fix for query param issue with base url (streamlit#2894) Add fuzzy search to selectbox (streamlit#2933) Informative repr methods for our python classes (streamlit#3027) ComponentInstance: handle iframe changes (streamlit#3015)
|
@kmcgrady That's great! Do you know when fuzzy search for multiselect will be merged? |
Adds fuzzy search to selectbox using fzy.js. This library performs the fuzzy match itself, and also scores each match so we can display the "best" matches first.
Here's PR preview, I've updated the default script with a convenient example.