【发布时间】:2012-11-10 11:59:14
【问题描述】:
3 个模型:
Class Product
include Mongoid::Document
has_many :orders, dependent: :destroy, :autosave => true
#search
searchable do
text :title, :description, :boost => 2.0
time :created_at
end
end
Class Order
include Mongoid::Document
belongs_to :product
has_one :dispute, dependent: :destroy, :autosave => true
end
Class Dispute
include Mongoid::Document
belongs_to :order
field :buyer_has_requested_refund, :type => Boolean, :default => "false"
end
我需要在products_controller.rb 对index 采取行动,获取并从高到低排序所有与buyer_has_requested_refund = true 有争议的订单产品
类似:
def index
@search = Product.solr_search do |s|
s.fulltext params[:search]
s.keywords params[:search]
s.order_by :disputes_where_buyer_has_requested_refund, :desc
end
@products = @search.results
respond_to do |format|
format.html # index.html.erb
end
end
谢谢!
【问题讨论】:
-
您在哪个模型中添加了用于索引这些对象的可搜索块。
-
在模型
Product.rb上。我已经编辑了问题并添加了可搜索块。非常感谢!
标签: ruby-on-rails ruby ruby-on-rails-3 solr sunspot