Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby MongoMapper-全文搜索_Ruby_Mongodb_Mongomapper - Fatal编程技术网

Ruby MongoMapper-全文搜索

Ruby MongoMapper-全文搜索,ruby,mongodb,mongomapper,Ruby,Mongodb,Mongomapper,直接在数据库上使用此命令,可以得到我想要的结果 db.products.find({$text: {$search: "some product"}}, {score: {$meta: "textScore"}}).sort({score:{$meta:"textScore"}}) 但在MongoMapper中使用它时,我会出错。 不带分数字段的搜索不会产生任何错误 @products = Product.where( '$text' => {'$search' => @s

直接在数据库上使用此命令,可以得到我想要的结果

db.products.find({$text: {$search: "some product"}}, {score: {$meta: "textScore"}}).sort({score:{$meta:"textScore"}})
但在MongoMapper中使用它时,我会出错。 不带分数字段的搜索不会产生任何错误

@products = Product.where(
    '$text' => {'$search' => @search_string}
)
但是,当我尝试添加排序字段时,会遇到问题

@products = Product.where(
    '$text' => {'$search' => @search_string}, :score => {'$meta' => "textScore"}
)
Mongo::操作失败/搜索未知运算符:$meta

使用原始查询方法也会失败

@products = MongoMapper.database['products'].find(
    '$text' => {'$search' => @search_string}, :score => {'$meta' => "textScore"}
)
我尝试运行的完整查询是

 @products = Product.where(
    '$text' => {'$search' => @search_string},:score => {'$meta' => "textScore"}
).sort(:score => {'$meta' => "textScore"}).limit(5)
这就产生了错误

Mongo::OperationFailure at/search对于所有$meta排序键必须具有$meta projection

有人对我的错误有什么建议吗?我想我用错了


已安装版本。MongoMapper(0.14.0,0.13.1)

MongoMapper谷歌小组的一位用户为我指出了正确的方向

@products = Product.where(
'$text' => {'$search' => @search_string}).fields(:score => {'$meta' => "textScore"})