Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A tiny lightweight library for Fuzzy Search

License

NotificationsYou must be signed in to change notification settings

ad1992/fuzzify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A tiny lightweight library for Fuzzy Search.

Why

I made this library as a result of learning aboutLevenshtein algorithm to calculate minimum number of edits required transform one word to another.

Note

Note: The library is at a very early stage, if you want tohelp improve it, please open anissue.

Installation

withyarn

yarn add fuzzify

withnpm

npm install fuzzify

Usage

importFuzyfrom"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.

AttributesDescription
textThe target string against which query is matched
distanceThe minimum number of edits (Instertion / Deletion / Replacement) 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,},];

Options

includeMatches

includeMatches - Determines whether theindices at which characters matche should be returned in the response. Eachmatch element consists of two indices -

  1. The index of query string where match is found.
  2. 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

  1. charactera at0th index inala matches with characatera at5th index inAustralia
  2. characterl at1st index inala matches with characatera at6th index inAustralia
  3. charactera at2nd index inala matches with characatera at8th index 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]],},];

Set up

Install packages:

yarn

Start development playground:

yarn start

Build command:

yarn build

Contributing

Please 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

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp