據我瞭解,自3.8.9版本開始,貓鼬支持全文搜索。但我找不到一個好的文檔!
我想要做的事,如:在貓鼬中使用重量進行全文搜索
db.collection.ensureIndex(
// Fields to index
{
animal: "text",
color: "text",
pattern: "text",
size: "text"
},
// Options
{
name: "best_match_index",
// Adjust field weights (default is 1)
weights: {
animal: 5, // Most relevant search field
size: 4 // Also relevant
}
}
)
我可以用純貓鼬做呢?或者我必須使用一些像mongoose-text-search這樣的插件?如果沒有重量?
我應該怎麼做?
你有沒有打過電話['index'(http://mongoosejs.com/docs/api.html#schema_Schema-index)在架構上添加文本索引? – JohnnyHK
我在schema中做了索引:'text',但是我想像上面的例子那樣在多個字段上索引。 –
不要在模式定義中聲明它,_call_模式的'index'方法。 http://mongoosejs.com/docs/api.html#schema_Schema-index – JohnnyHK