Nerian
Nerian

Reputation: 16177

How to do text search in Mongoid

How can I do this query in Mongoid?

db.users.find({ $text: { $search: "Something" } }, { score: { $meta: "textScore" } }).sort( { score: { $meta: "textScore" } } ) 

I tried doing:

User.where('$text' => { '$search' => "Something" }, score: { '$meta' => "textScore" }).entries 

But I get a failed with error 17287: "Can't canonicalize query: BadValue unknown operator: $meta”

Hope you can help.

Thanks

Upvotes: 2

Views: 788

Answers (1)

krsyoung
krsyoung

Reputation: 1241

Not a great answer but there is a monkey patch available that does work. Here is a link to the GitHub comment with the code to use:

https://github.com/mongoid/moped/issues/358#issuecomment-81156032

Upvotes: 2

Related Questions