查看 mauriciozaffari 的 mongoid_search gem。它应该为您提供更完整的搜索选项。它应该能够搜索关系。我也理解它会拆分由空格进行的搜索,因此您将进行更彻底的搜索,请在此处查看
希望能帮助到你。
编辑:
我自己并没有真正使用过它,但据我所知,您需要采取以下步骤:>/p?
1)在你的gemfile中安装gem
    gem 'mongoid_search' 
   (除非你使用mongoid 2.xx,在这种情况下将gem锁定在0.2.8)
2)从您要搜索的模型中添加
    class Product
      include Mongoid::Document
      include Mongoid::Search
      field :brand
      field :name
      has_many   :tags
      belongs_to :category
      search_in :brand, :name, :tags => :name, :category => :name
    end
    class Tag
      include Mongoid::Document
      field :name
      belongs_to :product
    end
    class Category
      include Mongoid::Document
      field :name
      has_many :products
    end
所以,据我所知,你在这里所说的基本上是;我有一个模型Product,它有字段brand和name.  Product可以有很多Tags并且可以有很多产品附加到一个Category. 然后你在产品模型中导入Mongoid::Search,定义你想要搜索的字段:Product fields -> brand and name也通过链接has many搜索name字段Tags并搜索name字段和我认为Category的模型!.
然后从这里您将能够调用:
Product.full_text_search("value")
它将搜索您的产品型号,name还有brand一些全文搜索选项,您应该从我放在上面链接中的 README.md 中查看它们。我认为最相关的是 relevant_search我认为允许您搜索模型关联
同样,我还没有使用过这个 gem,但这只是我从 README.md 中收集到的