您的位置:首页 > 数据库 > Mongodb

Fuzzy/Partial Search in MongoDB

2016-12-25 08:16 302 查看
http://stackoverflow.com/a/27984038/2177408

The text search feature in MongoDB (as at 2.6) does not have any built-in
features for fuzzy/partial string matching. As you've noted, the use case currently focuses on language & stemming support with basic boolean operators and word/phrase matching.

There are several possible approaches to consider for fuzzy matching depending on your requirements and how you want to qualify "efficient" (speed, storage, developer time, infrastructure required, etc):

Implement support for fuzzy/partial matching in your application logic using some of the readily available soundalike and similarity algorithms. Benefits of this approach include not having to add any extra infrastructure and being able to closely tune matching
to your requirements.

For some more detailed examples, see: Efficient Techniques
for Fuzzy and Partial matching in MongoDB.

Integrate with an external search tool that provides more advanced search features. This adds some complexity to your deployment and is likely overkill just for typeahead, but you may find other search features you would like to incorporate elsewhere in your
application (e.g. "like this", word proximity, faceted search, ..).

For example see: How to Perform Fuzzy-Matching with
Mongo Connector and Elastic Search. Note: ElasticSearch's fuzzy
query is based on Levenshtein distance.

Use an autocomplete library like Twitter's open source 
typeahead.js
,
which includes a suggestion engine and query/caching API. Typeahead is actually complementary to any of the other backend approaches, and its (optional) suggestion engine Bloodhound supports
prefetching as well as caching data in local storage.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: