Roh*_*nil 3 full-text-indexing mongodb
是否可以在 mongo 中对多个 $text 索引搜索使用 $and 运算符?
我的数据库的 tp 集合中有文档
> db.tp.find()
{ "_id" : ObjectId("...."), "name" : "tp", "dict" : { "item1" : "random", "item2" : "some" } }
{ "_id" : ObjectId("...."), "name" : "tp", "dict" : { "item3" : "rom", "item4" : "tttt" } }
Run Code Online (Sandbox Code Playgroud)
然后我做
> db.tp.createIndex({ "$**": "text" })
> db.tp.find({ $and: [{$text : { $search: "random" } }, {$text : { $search: "redruth" } }]})
Run Code Online (Sandbox Code Playgroud)
它失败了
Error: error: {
"waitedMS" : NumberLong(0),
"ok" : 0,
"errmsg" : "Too many text expressions",
"code" : 2
}
Run Code Online (Sandbox Code Playgroud)
但是文本索引搜索适用于单个搜索,所以不能用 $and 运算符绑定多个文本搜索吗?顺便说一下,我使用通配符$**进行索引,因为我想搜索整个文档。
小智 6
基于mongoDB文档,AND 运算符可以通过结合引用和空格直接在搜索词中使用。例如,我们搜索“ssl 证书”和“权限密钥”,所以查询应该是:
> db.tp.find({'$text': {'$search': '"ssl certificate" "authority key"'}})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3432 次 |
| 最近记录: |