-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add fuzzy search hook to @automattic/search
#65501
Conversation
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Async-loaded Components (~5237 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
@zaguiini What are some examples where fuzzy search (and a separate library) are advantageous over the pure string match in #65505 ? |
I'm not sure what's performance impact but I think fuzzy can be beneficial especially as list of sites grow. I might want to find a site that i do not remember the exact name but entering partial string finds the site for me. Is the search on cached results or any server call is made? |
I actually like this feature, there are particular sites I use at times but after I while it gets lost in recently used order, I often don't remember the name especially with the generated free domain names. Testing this out made it easy to find a site quickly that would otherwise take me sometime. |
Thanks, @vykes-mac. That's exactly the case I think fuzzy search should be used for. Furthermore, there's this great article here exemplifying use cases and why it's a good idea. So @danielbachhuber, the difference is mostly subjective as there are no performance benefits of one over the other. |
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.
0b3eb29
to
dfaf90a
Compare
@tyxla: added some tests. One enhancement is now that we're reusing the same Try it yourself: diff --git a/client/components/site-selector/index.jsx b/client/components/site-selector/index.jsx
index e010714eb9..a085c03c9e 100644
--- a/client/components/site-selector/index.jsx
+++ b/client/components/site-selector/index.jsx
@@ -416,7 +416,6 @@ export class SiteSelector extends Component {
>
<SearchComponent
onSearch={ this.onSearch }
- delaySearch={ true }
placeholder={ this.props.searchPlaceholder }
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={ this.props.autoFocus } Then open the sidebar > site search in Calypso. Please, re-review the PR! |
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.
Works well in my testing! Left some non-blocking comments.
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.
Looks like Fuse supports some powerful searching. Maybe in the future we'll want to expose the scores from the hook too, but we can do that when the need arises.
fuse.js
seems solid enough from a maintenance point of view. Apache licensed.
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.
Looking good 👍
Left a few comments, nothing blocking, and this can be shipped with or without addressing them IMHO.
Nice work 🚀
7c86ff6
to
cf3a033
Compare
cf3a033
to
b406375
Compare
@tyxla @danielbachhuber @vykes-mac @p-jackson would appreciate a review of the |
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.
README update looks great!
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.
Still looking great! Thanks for the thorough README and for the tests.
Just left a couple of little suggestions, but nothing blocking.
🚀
Proposed Changes
Right now, our client-side searches are pretty limited: we have the
searchSites
HOC that exposes basic search functionality that's not very customizable and the results have to match the term exactly, bringing a subpar user experience.This PR adds a
useFuzzySearch
hook that relies on thefuse.js
package. That hook can be used anywhere search is needed. You can pass fields that are indexed and the search state is also handled.Testing Instructions
Check out this branch, run
yarn install
thenyarn build-packages
so the@automattic/search
package gets updated.Once done, apply this diff to Calypso:
Open any site in Calypso, click
Switch Site
and start typing in the search bar. It no longer requires an exact match to return queried results.This is an optional change to the
searchSites
HOC just to exemplify the usage. It does not necessarily need to be used there. I first implemented this hook in #65454 but I moved it here so I don't have a PR breaking the single-subject rule.Related to #65169, first implemented in #65454.