fuzzify
v0.1.0
퍼지 검색을 위한 작고 가벼운 라이브러리입니다.
Vladimir Levenshtein이 한 단어를 다른 단어로 변환하는 데 필요한 단일 문자 편집(삽입, 삭제 또는 대체)의 최소 횟수를 계산하는 Levenshtein Distance 알고리즘에 대해 학습한 결과 이 라이브러리를 만들었습니다.
메모
참고: 라이브러리는 매우 초기 단계이므로 개선에 도움을 주고 싶다면 이슈를 열어주세요.
여기에서 데모를 확인할 수 있습니다.
yarn
와 함께
yarn add fuzzify
npm
으로
npm install fuzzify
import Fuzzy from "fuzzify" ;
const countries = [
"Australia" ,
"France" ,
"Germany" ,
"Hungary" ,
"Iceland" ,
"India" ,
"Israel" ,
"Italy" ,
"Japan" ,
"Malawi" ,
"Malaysia" ,
"Maldives" ,
] ;
const fuzzy = new Fuzzy ( countries ) ;
const query = "ala" ;
const results = fuzzy . search ( query ) ;
console . log ( "RESULTS" , results ) ;
search
API는 아래 형식으로 전달된 쿼리와 대략적으로 일치하는 문자열을 제공합니다.
속성 | 설명 |
---|---|
텍스트 | 쿼리와 일치하는 대상 문자열 |
거리 | 쿼리를 대상 텍스트로 변환하는 데 필요한 최소 편집 수(삽입/삭제/대체)입니다. |
[
{
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
includeMatches
- 문자가 일치하는 indices
응답에 반환해야 하는지 여부를 결정합니다. 각 match
요소는 두 개의 인덱스로 구성됩니다.
예 ?
query = "ala" , target string = "Australia"
matches : [
[ 0 , 5 ] ,
[ 1 , 6 ] ,
[ 2 , 8 ] ,
] ,
위의 예에서? 일치하는 항목이 발견되었습니다
ala
의 0th
인덱스에 있는 문자 a
는 Australia
의 5th
인덱스에 있는 문자 a
와 일치합니다.ala
의 1st
인덱스에 있는 문자 l
Australia
의 6th
인덱스에 있는 문자 a
와 일치합니다.ala
의 2nd
인덱스에 있는 문자 a
Australia
의 8th
인덱스에 있는 문자 a
와 일치합니다.완전한 응답은?
[
{
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 ] ] ,
} ,
] ;
includeScore
결과에 점수를 추가해야 하는지 여부를 결정합니다. 1
점은 정확히 일치함을 의미하고, 0
점은 일치하지 않음을 의미하며 해당 옵션은 결과에서 제거됩니다. 결과에서 모든 옵션을 얻으려면 문제를 열고 토론해 보세요.
caseSensitive
쿼리가 대소문자를 구분해야 하는지 여부를 결정합니다. 기본적으로 이 옵션은 false
입니다.
패키지를 설치합니다:
yarn
개발 플레이그라운드 시작:
yarn start
빌드 명령:
yarn build
논의를 시작할 수 있도록 문제를 열어주세요. 도서관 개선을 위한 어떤 도움이라도 환영합니다 :).