Quickly Implement Fuzzy Searching in your Software Application

Search functionalities are vital for software applications but can be challenging to implement. For this reason, you can use a Javascript-based library called Fuse.js to implement a user-friendly search.

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

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.

Usage:

  • 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.

Try Full Demo here.

As you can see, it will return the nearest possible match from the search parameter.

Conclusion

Now, although Fuse.js is awesome, it does have some limitations. Being a JavaScript search library, it can only do so much on the backend and the frontend side of your application. For instance, searching a JSON dataset can be resource intensive, and is not ideal for critical applications that deal with a large amount of data. For small to medium-scale applications, however, Fuse.js is highly recommended. You can learn more about it here.