我在我的应用程序中使用 mongo 文本搜索。
指数:
db.test.createIndex(
{
title: 'text',
description: 'text'
},
{
name: "TextIndex",
weights: {
title: 10,
description: 1
}
}
)
分数:
title : 10
description : 1
文档:
db.test.insert(
[
{ _id: 1, title: "agent de production", description: "production or agent"},
{ _id: 2, title: "agent test production", description: "agent" },
{ _id: 3, title: "production agent", "description" : "production"},
{ _id: 4, title: "agent", "description" : "production"},
{ _id: 5, title: "test", "description" : "production example agent"},
]
)
问题
所以如果我搜索“代理生产”
结果应该是
[
{ _id: 1, title: "agent de production", description: "production or agent"},
{ _id: 2, title: "agent test production", description: "agent" },
{ _id: 3, title: "production agent", "description" : "production"},
{ _id: 5, title: "test", "description" : "production example agent"},
]
我试过的:
db.test.find({"$text" : {"$search" : "\"agent production\""}}); Query result does not match with the expected result.
结果:无
查询短语: db.test.find({"$text" : {"$search" : "\"agent\" \"production\""}})
结果:
{ "_id" : 5, "title" : "test", "description" : "production example agent" }
{ "_id" : 1, "title" : "agent de production", "description" : "production or agent" }
{ "_id" : 3, "title" : "production agent", "description" : "production" }
{ "_id" : 2, "title" : "agent test production", "description" : "agent" }
{ "_id" : 4, "title" : "agent", "description" : "production" }
任何建议将不胜感激。