Constructor
# new FuzzySearch()
- Version:
- 1.0.0
- Copyright:
- 2022 Nicolas Dufresne, RxLaboratory
- License:
- GNU-GPLv3
Example
// Encapsulate everything to avoid global variables!
(function() {
#include "fuzzy-search.jsxinc"
var people = [{
name: {
firstName: 'Jesse',
lastName: 'Bowen',
},
state: 'Seattle',
}];
var searcher = new FuzzySearch(people, ['name.firstName', 'state'], {
caseSensitive: true,
});
var result = searcher.search('ess');
})();
Methods
# static match(item, query, caseSensitiveopt) → {float}
Caculates the score of a string against a query
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
item |
string
|
The string to test | ||
query |
string
|
The string to search | ||
caseSensitive |
bool
|
<optional> |
false | Whether to check the case or not |
The score, a positive value.
-
-
-
-
0
: no match-
1
: perfect match-
>1
: the lower the score, the better the matchfloat
# search(query) → {Array.<Obbject>}
Searches for items in the haystack
Parameters:
Name | Type | Description |
---|---|---|
query |
string
|
The string to search |
The matching results. Objects with two attributes:
item
and score
.Array.<Obbject>