This specifically affects Text Searches within Mongoid, which can limit their utility with associated Gems such as kaminari-mongoid. Note that sorting by Text Search score requires an object as opposed to single field ordering which require an integer to indicate direction.
For example:
require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'mongoid' end Mongoid.configure do |config| config.clients.default = { uri: "mongodb://localhost:27017/test" } end class Band include Mongoid::Document field :name, type: String field :description, type: String index description: 'text' end Band.collection.drop Band.create! Band.create_indexes begin Band.where('$text' => {'$search' => 'ounces'}).order(score: { '$meta' => 'textScore' }) rescue => ex puts ex puts ex.backtrace end
# output undefined method `to_direction' for {"$meta"=>"textScore"}:Hash Did you mean? to_criteria /Users/alex/.rvm/gems/ruby-2.7.5/gems/mongoid-8.0.2/lib/mongoid/criteria/queryable/extensions/hash.rb:121:in `block (2 levels) in __sort_option__' /Users/alex/.rvm/gems/ruby-2.7.5/gems/mongoid-8.0.2/lib/mongoid/criteria/queryable/extensions/hash.rb:117:in `each_pair' /Users/alex/.rvm/gems/ruby-2.7.5/gems/mongoid-8.0.2/lib/mongoid/criteria/queryable/extensions/hash.rb:117:in `block in __sort_option__' /Users/alex/.rvm/gems/ruby-2.7.5/gems/mongoid-8.0.2/lib/mongoid/criteria/queryable/extensions/hash.rb:116:in `tap' /Users/alex/.rvm/gems/ruby-2.7.5/gems/mongoid-8.0.2/lib/mongoid/criteria/queryable/extensions/hash.rb:116:in `__sort_option__' /Users/alex/.rvm/gems/ruby-2.7.5/gems/mongoid-8.0.2/lib/mongoid/criteria/queryable/optional.rb:172:in `block (2 levels) in order_by' /Users/alex/.rvm/gems/ruby-2.7.5/gems/mongoid-8.0.2/lib/mongoid/criteria/queryable/optional.rb:171:in `each' /Users/alex/.rvm/gems/ruby-2.7.5/gems/mongoid-8.0.2/lib/mongoid/criteria/queryable/optional.rb:171:in `block in order_by' /Users/alex/.rvm/gems/ruby-2.7.5/gems/mongoid-8.0.2/lib/mongoid/criteria/queryable/optional.rb:340:in `block in option' /Users/alex/.rvm/gems/ruby-2.7.5/gems/mongoid-8.0.2/lib/mongoid/criteria/queryable/optional.rb:338:in `tap' /Users/alex/.rvm/gems/ruby-2.7.5/gems/mongoid-8.0.2/lib/mongoid/criteria/queryable/optional.rb:338:in `option' /Users/alex/.rvm/gems/ruby-2.7.5/gems/mongoid-8.0.2/lib/mongoid/criteria/queryable/optional.rb:170:in `order_by' /Users/alex/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/forwardable.rb:235:in `order' text_search.rb:24:in `<main>'