2014-02-28 2 views

답변

2

하면 Levenshtein Distance 알고리즘을 사용 https://atmospherejs.com/perak/fuzzy-search 있습니다. 추가 정보에서 가져온 예 :

// If we have a collection named "Drinks" which contains "beer", "juice" and "milk" 

var searchString = "bear"; // user typed "bear" instead of "beer" 

// search "Drinks" collection for string "bear" 
var someCursor = Drinks.find({ drink_name: searchString }); 

// "bear" is not found, so we want to find most similar word to give user suggestion (Did you mean...) 
if(someCursor.count() == 0) 
{ 
    // expose entire collection 
    var tempCursor = Drinks.find({ }, { drink_name: true }); 

    // find most similar string 
    var bestWord = mostSimilarString(tempCursor, "drink_name", searchString, -1, false); 

    // in this example, bestWord is "beer", show user a suggestion: "Did you mean beer?" 
    // ... 
} 

등도 매우 강력하지만, 처음 사용할 어려워 보일 수있는 Elastic Searchhttps://github.com/Crenshinibon/spomet를 사용 https://atmospherejs.com/matteodem/easy-search 같은 다른 대안도있다.