Install
openclaw skills install fusejsImplement fuzzy search in JavaScript/TypeScript projects using Fuse.js. Use when users need client-side search, fuzzy matching, search highlighting, multi-field weighted search, tokenized search, or Web Worker parallel search.
openclaw skills install fusejsA zero-dependency TypeScript library based on the Bitap algorithm. Works in browsers, Node.js, and Deno.
npm install fuse.js # Full version
npm install fuse.js@beta # Includes FuseWorker
import Fuse from 'fuse.js' // ESM full version
import Fuse from 'fuse.js/basic' // Basic version (fuzzy search only)
const fuse = new Fuse(list, {
keys: ['title', 'author'],
includeScore: true, // Returns score 0-1
threshold: 0.4, // 0=exact match, 1=any match (0.3-0.4 recommended for search-as-you-type)
})
fuse.search('jon') // → [{ item, score, refIndex }]
new Fuse(list, {
keys: ['name'],
threshold: 0.4,
ignoreLocation: true, // MUST enable for long text, otherwise only searches ~first 60 chars
includeMatches: true, // For highlighting
includeScore: true,
minMatchCharLength: 2, // Ignores single-character matches
})
keys: [
{ name: 'title', weight: 2 },
{ name: 'description', weight: 1 },
]
Dot notation: 'author.firstName'. Set ignoreFieldNorm to disable the short-field bonus.
{ useExtendedSearch: true }
fuse.search('^java =exact') // space=AND, |=OR
fuse.search("!deprecated | 'active")
Operators: no prefix=fuzzy, ==exact, '=contains, !=exclude, ^=prefix, .$=suffix. Requires Fuse.use(ExtendedSearch) for the basic version.
{
useTokenSearch: true,
tokenMatch: 'any' // 'any'(OR, default) | 'all'(AND filtering)
}
Multi-word queries are split into independent tokens for fuzzy matching + IDF weighting. Word order is irrelevant, and there is no 32-character length limit. Use the tokenize function + Intl.Segmenter for CJK tokenization. Full version only.
fuse.search({
$and: [{ title: 'js' }, { $or: [{ author: 'a' }, { author: 'b' }] }]
})
includeMatches: true → result.matches[].indices → [[start, end], ...]. Note: end is inclusive.
fuse.add(doc)
fuse.remove(doc => doc.id === 'x')
Fuse.match('patern', 'pattern matching') // → { isMatch, score, indices }
import { FuseWorker } from 'fuse.js/worker'
const fuse = new FuseWorker(docs, { keys: ['title'] })
const r = await fuse.search('q')
fuse.terminate() // Must clean up
With 4 workers + 100K documents: approximately 3.3x speedup. Browser only. Does not support sortFn/getFn/useTokenSearch.
Load as needed:
ignoreLocation: true for long text.useTokenSearch for long queries.search() method returns a Promise. Does not support function options.