尽管 MongoDB 现在支持 "高级 "全文解决方案,但只有在使用 Atlas 托管数据时才有效。
参考:https://www.mongodb.com/docs/atlas/atlas-search/
https://www.mongodb.com/docs/manual/text-search/
https://www.mongodb.com/docs/manual/reference/text-search-languages/
现在,2024年,你只需要用Percona替换MongoDB 社区版,即可轻松实现全文索引功能。
【演示】- 【支持中文分词】
db.t1.createIndex({info: "text"}, {default_language: "ngram"})
db.t1.getIndexes()
db.t1.find({ $text: { $search: "热爱" } })
db.t1.find({ $text: { $search: "热爱" } }).explain().queryPlanner.winningPlan
你可以告别正则表达式了
db.t1.find({ "info": { $regex: eval("/热爱/") }}).explain().queryPlanner.winningPlan