MongoDB全文搜索+用于部分单词匹配的解决方法 [英] MongoDB fulltext search + workaround for partial word match
问题描述
由于无法通过使用mongodb全文搜索来查找blue这个词的blueberry,我想帮助我的用户完成blue一词到blueberry。为此,是否可以查询mongodb全文索引中的所有单词 - >我可以使用这些单词作为建议,即typeahead.js?
文字搜索中的语言词汇使用算法尝试关联从一个共同基础派生的词(例如跑步应该与跑步相匹配)。这与您要为自动完成功能实现的前缀匹配(例如,蓝色匹配蓝莓)不同。
为了最有效地使用 typeahead.js
与MongoDB文本搜索我建议重点关注 prefetch
在typeahead中的支持:
-
创建一个
关键字
集合,其中包含您的集合中使用的常用词(可能包含使用频率计数)。您可以通过运行Map / Reduce 在整个集合中,您有文本搜索索引,并使用定期更新来保持单词列表的最新状态添加新文档时增量映射/减少/ / rel =noreferrer> Incremental Map / Reduce 。 code>关键字集合与唯一关键字(可能仅限于基于词频的流行关键词,以使列表易于管理/相关)。
然后,您可以使用生成的关键字JSON进行客户端自动完成,并使用typeahead的 prefetch
功能:
$('。mysearch .typeahead')。typeahead({
名称:'mysearch',
prefetch: '/data/keywords.json'
});
typeahead.js
会缓存 prefetch
localStorage中的JSON数据用于客户端搜索。当提交搜索表单时,您的应用程序可以使用服务器端 MongoDB文本搜索以相关顺序返回完整结果。
Since it is not possible to find "blueberry" by the word "blue" by using a mongodb full text search, I want to help my users to complete the word "blue" to "blueberry". To do so, is it possible to query all the words in a mongodb full text index -> that I can use the words as suggestions i.e. for typeahead.js?
Language stemming in text search uses an algorithm to try to relate words derived from a common base (eg. "running" should match "run"). This is different from the prefix match (eg. "blue" matching "blueberry") that you want to implement for an autocomplete feature.
To most effectively use typeahead.js
with MongoDB text search I would suggest focusing on the prefetch
support in typeahead:
Create a
keywords
collection which has the common words (perhaps with usage frequency count) used in your collection. You could create this collection by running a Map/Reduce across the collection you have the text search index on, and keep the word list up to date using a periodic Incremental Map/Reduce as new documents are added.Have your application generate a JSON document from the
keywords
collection with the unique keywords (perhaps limited to "popular" keywords based on word frequency to keep the list manageable/relevant).
You can then use the generated keywords JSON for client-side autocomplete with typeahead's prefetch
feature:
$('.mysearch .typeahead').typeahead({
name: 'mysearch',
prefetch: '/data/keywords.json'
});
typeahead.js
will cache the prefetch
JSON data in localStorage for client-side searches. When the search form is submitted, your application can use the server-side MongoDB text search to return the full results in relevance order.
这篇关于MongoDB全文搜索+用于部分单词匹配的解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!