rails 4 个带条件枚举的太阳黑子
rails 4 sunspot with enum where conditional
我已将我的模型配置为可由太阳黑子搜索:
enum status: [ :draft, :unreviewed, :reviewed, :publish, :disable, :reject ]
searchable do
text :name, :boost => 5
text :description
integer :status
time :created_at
end
在控制器中:
@search = Product.search do
fulltext params[:search]
with :status, 3
order_by :created_at, :desc
paginate :page => params[:page], :per_page => 10
end
这一行 with :status, 3
曾经是状态为 publish
的过滤器产品,这是我使用 rails 枚举设置的。但是我没有结果。
我错过了什么?谢谢
只需对您的控制器进行小改动
@search = Product.search do
fulltext params[:search]
with(:status).equal_to(3)
order_by :created_at, :desc
paginate :page => params[:page], :per_page => 10
end
和
rake sunspot:reindex
重新索引您的数据
这些是您可以使用的不同类型
with(:blog_id, 1)
with(:blog_id).equal_to(1)
with(:average_rating, 3.0..5.0)
with(:average_rating).between(3.0..5.0)
with(:category_ids, [1, 3, 5])
with(:category_ids).any_of([1, 3, 5])
我已将我的模型配置为可由太阳黑子搜索:
enum status: [ :draft, :unreviewed, :reviewed, :publish, :disable, :reject ]
searchable do
text :name, :boost => 5
text :description
integer :status
time :created_at
end
在控制器中:
@search = Product.search do
fulltext params[:search]
with :status, 3
order_by :created_at, :desc
paginate :page => params[:page], :per_page => 10
end
这一行 with :status, 3
曾经是状态为 publish
的过滤器产品,这是我使用 rails 枚举设置的。但是我没有结果。
我错过了什么?谢谢
只需对您的控制器进行小改动
@search = Product.search do
fulltext params[:search]
with(:status).equal_to(3)
order_by :created_at, :desc
paginate :page => params[:page], :per_page => 10
end
和
rake sunspot:reindex
重新索引您的数据
这些是您可以使用的不同类型
with(:blog_id, 1)
with(:blog_id).equal_to(1)
with(:average_rating, 3.0..5.0)
with(:average_rating).between(3.0..5.0)
with(:category_ids, [1, 3, 5])
with(:category_ids).any_of([1, 3, 5])