When to use Fuzzy searching?
Fuzzy search is a search behavior that allows users to search for data in a software application dataset, even if they have no, incomplete, or incorrect information about what they are looking for. If you think about it, it is the best way to implement searching in any application.
The best example of this behavior is a Google search where you can provide vague search queries or even misspelled words, but it will still try to give you the best result.
Fuse.js is the library we are exploring today because it is fast, lightweight, has zero dependencies, and can work on both the backend and frontend sides of your application. What’s more, it is super easy to get started. Finally, it returns the closest possible result for search queries, even for misspelled ones.
- You can begin by downloading Fuse.js using yarn or NPM
You can then proceed to import it into your file as shown below:
From here you can define a JSON object that you want to search, then create a Fuse.js instance where you can pass the object to search and keys that you would like Fuse.js to focus on.
As you can see, it will return the nearest possible match from the search parameter.