These tools implement different query models. Choose document indexing, approximate record search, finder-style ranking or a boolean ordered-character match according to the interface users expect.
A document search box, command palette and simple list filter can all be called fuzzy search. They do not necessarily need the same matching model or returned data.
elasticlunr builds a local index around documents, configured fields and a text-processing pipeline. It is useful when token-oriented retrieval and field relevance fit the content. Keep document references and index updates aligned with the source collection. This JavaScript package is not a hosted search service or a client that automatically provisions an Elasticsearch server.
Fuse.js searches strings or selected record fields using configurable approximate matching. Weights, thresholds and result options affect inclusion and ordering. Choose and test the desired typo behavior rather than assuming every similarly named library has the same algorithm.
fuzzysearch takes a query and target and returns true or false when the query characters occur in order, possibly with gaps. It is case-sensitive and accepts an empty query. It does not supply a ranked collection, scores or match positions; the application supplies those surrounding operations.
fuzzy-search wraps ordered-character matching across strings or selected object fields. By default it ignores case and preserves input order; sorting is an explicit option. Its search method returns the matched items, not a calibrated relevance object. An empty query returns the original collection.
fuzzysort provides collection search, prepared targets and snapshots, with result scores and matched indexes. The current score increases toward a closer match, with an exact match at 1. Collection results default to a limit of 10; limit 0 requests no cap, and total records the number before limiting. Do not mistake a displayed page of matches for the complete result set.
Use the product's abbreviations, names, misspellings, case and languages to compare results. Subsequence matching is not automatic edit-distance correction. Score meanings, directions and thresholds differ between engines and cannot be copied as equivalent probabilities.
Choose the smallest model that supplies the needed query semantics and presentation data. Index maintenance, dataset changes and highlighting are part of integration, not reasons to promise that every local matcher is a full remote search platform.
Choose ranked finder-style matches with original objects, matched positions and highlighting when abbreviated input is the intended interaction.
Choose configurable approximate search over strings or object fields when typo-oriented matching and result options fit the product.
Choose an ordered-character collection filter, enabling sorting only when that behavior is wanted.
Choose a case-sensitive boolean subsequence predicate when the application owns filtering, ranking and presentation.
Choose a local document index with fields and a text-processing pipeline when token-oriented full-text retrieval fits the content.
Fast, tiny, good fuzzy search for JavaScript.
<1ms for 13,000 files · 0 dependencies · clean ranking
https://farzher.github.io/fuzzysort/test/test.html

npm i fuzzysort
import fuzzysort from 'fuzzysort'
Browser:
<script type="module">
import fuzzysort from 'https://cdn.jsdelivr.net/npm/[email protected]/fuzzysort.min.js'
</script>
const files = [
{file: 'Guide.cpp'},
{file: 'UserInterface.cpp'},
]
const results = fuzzysort.go('ui', files, {key: 'file'})
results[0].obj.file // 'UserInterface.cpp'
fuzzysort.go(search, targets, {
limit : 10, // Max results; 0 = unlimited
threshold : .5, // Minimum score; 0 = any match
key : null, // Search one property
keys : null, // Search multiple properties
scoreFn : null, // Override result scoring
})
const result = fuzzysort.single('query', 'some string that contains my query.')
result.score // .80 (1 is a perfect match. 0.5 is a good match. 0 is no match.)
result.target // 'some string that contains my query.'
result.indexes // [29, 30, 31, 32, 33]
result.obj // reference to your original obj when using options.key
result.highlight('<b>', '</b>') // 'some string that contains my <b>query</b>.'
result.highlight((m, i) => <react key={i}>{m}</react>)
const objects = [{
title: 'Petaya Berry',
meta: {desc: 'Raises Special Attack when HP is low.'},
tags: ['berries', 'items'],
}, {
title: 'Liechi Berry',
meta: {desc: 'Raises Attack when HP is low.'},
favorite: true,
}]
const targets = fuzzysort.snapshot(objects, {
keys: ['title', 'meta.desc', obj => obj.tags?.join()],
})
const results = fuzzysort.go('attack berry', targets, {
scoreFn: r => r.score * (r.obj.favorite ? 2 : 1),
})
const result = results[0]
result[0].highlight() // 'Liechi <b>Berry</b>'
result[1].highlight() // 'Raises <b>Attack</b> when HP is low.'
result.obj.title // 'Liechi Berry'
Filter out targets you don't need to search! Especially long ones!
let targets = [
{file: 'Guide.cpp'},
{file: 'UserInterface.cpp'},
].filter(t => t.file.length < 1000)
If your targets don't change, take an immutable snapshot() for the best performance!
targets = fuzzysort.snapshot(targets, {key: 'file'})
fuzzysort.go('gotta', targets)
fuzzysort.go('go', targets)
fuzzysort.go('fast', targets)
If you can't snapshot, provide prepared targets instead of raw strings!
targets.forEach(t => t.filePrepared = fuzzysort.prepare(t.file))
fuzzysort.go('fast', targets, {key: 'filePrepared'})
Searches use NFKD normalization, strip diacritics, and remap common quote, dash, slash, ellipsis, and lookalike characters.
Add or override mappings with fuzzysort.remap():
fuzzysort.remap({',': '.'}) // 12,5 = 12.5
Structured cloning can remove the getters on results. For cloned results use:
fuzzysort.score(result)
fuzzysort.highlight(result)
fuzzysort.snapshot() for the best search performancefuzzysort.score() and fuzzysort.highlight() for Web Worker supportfuzzysort.remap() for custom normalizationthreshold and limitoptions.all; empty search now returns resultsscoreFn now works with all search modes