- v6.4.1Latest
- v6.4.0
- v6.3.1
- v6.3.0
- v6.2.1
- v6.2.0
- v6.2.0-beta.1
- v6.2.0-beta.0
- v6.1.0
- v6.1.0-alpha.2
- v6.1.0-alpha.1
- v6.1.0-alpha.0
- v6.0.4
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0.0
- v6.0.0-beta.2
- v6.0.0-beta.1
- v6.0.0-beta.0
- v5.2.3
- v5.2.2
- v5.2.2-alpha.0
- v5.2.1
- v5.2.0
- v5.2.0-alpha.6
- v5.2.0-alpha.5
- v5.2.0-alpha.4
- v5.2.0-alpha.3
- v5.2.0-alpha.2
- v5.2.0-alpha.1
- v5.2.0-alpha.0
- v5.1.0
- v5.0.10-beta
- v5.0.9-beta
- v5.0.8-beta
- v5.0.7-beta
- v5.0.6-beta
- v5.0.5-beta
- v5.0.4-beta
- v5.0.3-beta
- v5.0.2-beta
- v5.0.1-beta
- v5.0.0-beta
- v4.1.0-beta
- v4.0.4-beta
- v4.0.3-beta
- v4.0.2-beta
- v4.0.1-beta
- v4.0.0-beta
- v3.6.1
- v3.6.0
- v3.5.0
- v3.4.6
- v3.4.5
- v3.4.4
- v3.4.3
- v3.4.2
- v3.4.1
- v3.4.0
- v3.3.1
- v3.3.0
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.7.4
- v2.7.3
- v2.7.2
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.0
- v2.4.1
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.0-beta
- v2.0.2
- v2.0.1
- v2.0.0
- v1.3.1
- v1.3.0
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.0
- v1.0.1
- v
- show
- ls
- l
- 2.0.1
- 1.2.2
- 1.2.1
Fuse.js
Lightweight fuzzy-search, in JavaScript, with zero dependencies
Check out the demo & usage
Table of Contents
Options
keys (type: Array
)
List of properties that will be searched. This also supports nested properties:
var books = [{
title: "Old Man's War"
author: {
firstName: "John",
lastName: "Scalzi"
}
}];
var fuse = new Fuse(books, { keys: ["title", "author.firstName"] });
id (type: String
)
The name of the identifier property. If specified, the returned result will be a list of the items’ identifiers, otherwise it will be a list of the items.
caseSensitive (type: Boolean
, default: false
)
Indicates whether comparisons should be case sensitive.
include (type: Array
, default: []
)
An array of values that should be included from the searcher’s output. When this array contains elements, each result in the list will be of the form { item: ..., include1: ..., include2: ... }
. Values you can include are score
, matches
. Ex:
{ include: ['score', 'matches' ] }
shouldSort (type: Boolean
, default: true
)
Whether to sort the result list, by score.
searchFn (type: Function
, default: BitapSearcher
)
The search function to use. Note that the search function ([[Function]]
) must conform to the following API:
/*
@param pattern The pattern string to search
@param options The search option
*/
[[Function]].constructor = function(pattern, options) { ... }
/*
@param text: the string to search in for the pattern
@return Object in the form of:
- isMatch: boolean
- score: Int
*/
[[Function]].prototype.search = function(text) { ... }
getFn (type: Function
, default: Utils.deepValue
)
The get function to use when fetching an object’s properties. The default will search nested paths ie foo.bar.baz
/*
@param obj The object being searched
@param path The path to the target property
*/
// example using an object with a `getter` method
getFn: function (obj, path) {
return obj.get(path);
}
sortFn (type: Function
, default: Array.prototype.sort
)
The function that is used for sorting the result list.
location (type: Integer
, default: 0
)
Determines approximately where in the text is the pattern expected to be found.
threshold (type: Decimal
, default: 0.6
)
At what point does the match algorithm give up. A threshold of 0.0
requires a perfect match (of both letters and location), a threshold of 1.0
would match anything.
distance (type: Integer
, default: 100
)
Determines how close the match must be to the fuzzy location (specified by location
). An exact letter match which is distance
characters away from the fuzzy location would score as a complete mismatch. A distance
of 0
requires the match be at the exact location
specified, a distance
of 1000
would require a perfect match to be within 800 characters of the location
to be found using a threshold
of 0.8
.
maxPatternLength (type: Integer
, default: 32
)
The maximum length of the pattern. The longer the pattern, the more intensive the search operation will be. Whenever the pattern exceeds the maxPatternLength
, an error will be thrown. Why is this important? Read this.
verbose (type: Boolean
, default: false
)
Will print to the console. Useful for debugging.
tokenize (type: Boolean
, default: false
)
When true, the search algorithm will search individual words and the full string, computing the final score as a function of both. Note that when tokenize
is true
, the threshold
, distance
, and location
are inconsequential for individual tokens.
tokenSeparator (type: Regex
, default: / +/g
)
Regex used to separate words when searching. Only applicable when tokenize
is true
.
matchAllTokens (type: Boolean
, default: false
)
When true
, the result set will only include records that match all tokens. Will only work if tokenize
is also true.
Methods
search(/*pattern*/)
@param {String} pattern The pattern string to fuzzy search on.
@return {Array} A list of all search matches.
Searches for all the items whose keys (fuzzy) match the pattern.
set(/*list*/)
@param {Array} list
@return {Array} The newly set list
Sets a new list for Fuse to match against.
Weighted Search
In some cases you may want certain keys to be weighted differently:
var fuse = new Fuse(books, {
keys: [{
name: 'title',
weight: 0.3
}, {
name: 'author',
weight: 0.7
}],
});
Where 0 < weight <= 1
Contributing
Coding conventions
Code should be run through Standard Format.
Testing
Before submitting a pull request, please add relevant tests in test/fuse-test.js
, and execute them via npm test
.
Note that ALL TESTS MUST PASS, otherwise the pull request will be automatically rejected.