【发布时间】:2014-01-07 14:41:15
【问题描述】:
在 MongoDB 中进行全文搜索和部分搜索的正确方法是什么? 例如。挪威语“sokk”(袜子)。 搜索“sokk”时,我想匹配“sokker”(复数形式的袜子)、“sokk”和“sokkepose”
搜索“sokker”应匹配“sokk”和“sokker”。
我通过使用这个 ruby sn-p 得到了想要的结果:
def self.search(q)
result = []
# Full text search first
result << Ad.text_search(q).to_a
# Then search for parts of the word
result << Ad.any_of({ title: /.*#{q}.*/i }, { description: /.*#{q}.*/i} ).to_a
result.flatten!
result.uniq
end
有什么建议吗? :)
干杯,
马丁·斯塔本费尔特
【问题讨论】:
标签: ruby mongodb full-text-search mongoid partial