What can Fuse.js search?
Give Fuse.js a list of records and tell it which fields to read, such as a product name or a short description. It builds a search index from that list and ranks near matches when someone types. You still build the search box and decide what a result opens.
If an exact word deep inside a long description goes missing, check Fuse’s location setting. It favors matches near the start by default. You can turn that preference off and give names more weight than descriptions if that fits what visitors look for.
What should stay out of the browser list?
Send only the records and fields that the person is allowed to read. The browser already has the list before Fuse.js decides which results to show. Hiding a result on the page leaves the underlying record in the browser.
For a shared collection of private invoices, have your server check the signed-in account and search the records that account may read. A public list of product names can use the browser version without downloading private notes.
Can a typo and a missing accent find the same product?
In a scratch folder, install Fuse.js 7.5.0. Save this as check.mjs and run node check.mjs. The example uses two invented products in memory and makes no network requests when it runs.
import Fuse from 'fuse.js'
const products = [
{ name: 'Café Ceramic Mug' },
{ name: 'Canvas Tote' },
]
const search = new Fuse(products, {
keys: ['name'],
threshold: 0.3,
ignoreLocation: true,
ignoreDiacritics: true,
})
for (const query of ['ceramc mug', 'cafe', 'telephone']) {
console.log(query, search.search(query).map(({ item }) => item.name))
}- Compare two close spellingsSearch for ceramc mug and then cafe. Both should return Café Ceramic Mug. The accent setting lets cafe match Café.
- Check a word that is absentSearch for telephone. The result should be empty. If unrelated names start appearing when you loosen the match setting, tighten it again and repeat the examples.
What changes when the list grows or a product is removed?
Fuse.js is an Apache-2.0 licensed library. There is no per-query bill for running it yourself. Count the bytes the browser downloads for the list, and measure how long it takes to start and respond on the kind of phone visitors use. More records and longer fields make search do more work.
When a product changes, update the list the app loads and rebuild the index or update the in-memory collection. If you ship a prebuilt index, publish it with the same version and ordering of the list it was built from. Keep the original records and field choices so you can rebuild or switch tools.