Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork6
A tiny lightweight library for Fuzzy Search
License
ad1992/fuzzify
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A tiny lightweight library for Fuzzy Search.
I made this library as a result of learning aboutLevenshtein Distance algorithm to calculate the minimum number of single-character edits (insertions, deletions or substitutions) required to transform one word to another byVladimir Levenshtein.
Note
Note: The library is at a very early stage so if you want toTo help improve it, please open anissue.
You can check the demohere.
withyarn
yarn add fuzzify
withnpm
npm install fuzzify
importFuzzyfrom"fuzzify";constcountries=["Australia","France","Germany","Hungary","Iceland","India","Israel","Italy","Japan","Malawi","Malaysia","Maldives",];constfuzzy=newFuzzy(countries);constquery="ala";constresults=fuzzy.search(query);console.log("RESULTS",results);
Thesearch API gives approximate matched strings with the passed query in the below format.
| Attributes | Description |
|---|---|
| text | The target string against which the query is matched |
| distance | The minimum number of edits (Insertion / Deletion / Substitutions) required to transform the query to target text. |
[{text:"Malawi",distance:3,},{text:"Malaysia",distance:5,},{text:"Australia",distance:6,},{text:"Italy",distance:3,},{text:"Japan",distance:3,},{text:"Iceland",distance:5,},{text:"Maldives",distance:6,},{text:"Israel",distance:5,},{text:"India",distance:4,},{text:"France",distance:5,},{text:"Germany",distance:6,},{text:"Hungary",distance:6,},];
includeMatches - Determines whether theindices at which characters match should be returned in the response.Eachmatch element consists of two indices -
- The index of query string where match is found.
- The index of target string where a match is found.
Example 👇
query="ala",targetstring="Australia"matches:[[0,5],[1,6],[2,8],],
In the above example 👇 matches are found
- character
aat0thindex inalamatches with characateraat5thindex inAustralia - character
lat1stindex inalamatches with characateraat6thindex inAustralia - character
aat2ndindex inalamatches with characateraat8thindex inAustralia
The complete response would be 👇
[{text:"Malawi",distance:3,matches:[[0,1],[1,2],[2,3],],},{text:"Malaysia",distance:5,matches:[[0,1],[1,2],[2,7],],},{text:"Australia",distance:6,matches:[[0,5],[1,6],[2,8],],},{text:"Italy",distance:3,matches:[[0,2],[1,3],],},{text:"Japan",distance:3,matches:[[0,1],[2,3],],},{text:"Iceland",distance:5,matches:[[1,3],[2,4],],},{text:"Maldives",distance:6,matches:[[0,1],[1,2],],},{text:"Israel",distance:5,matches:[[0,3],[1,5],],},{text:"India",distance:4,matches:[[2,4]],},{text:"France",distance:5,matches:[[2,2]],},{text:"Germany",distance:6,matches:[[2,4]],},{text:"Hungary",distance:6,matches:[[2,4]],},];
Determines whether a score should be added in the result. A score of1 means an exact match, however a score of0 meansno match and those options are removed from the result.If you want to get all the options in the result, please open anissue and let's discuss.
Determines whether the query should be case-sensitive or not.By default, this option isfalse.
Install packages:
yarnStart development playground:
yarn startBuild command:
yarn buildPlease open anissue so we can start discussing. Any help to improve the library is most welcome :).
About
A tiny lightweight library for Fuzzy Search
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.