模糊搜索集合的最佳解决方案/包?

时间:2014-02-28 20:38:38

标签: meteor

有人能指出我在正确的方向上找到一个好的模糊搜索解决方案或包吗?我希望能够搜索几个集合,包括Meteor.users。

由于

1 个答案:

答案 0 :(得分:2)

https://atmospherejs.com/perak/fuzzy-search使用Levenshtein Distance算法。摘自自述文件的一个例子:

// 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?"
    // ...
}

还有其他替代方案,例如https://atmospherejs.com/matteodem/easy-search,它使用Elastic Searchhttps://github.com/Crenshinibon/spomet,它也非常强大,但最初可能看起来更难使用。