0

In my project am trying to display products based on user choice. User can check which department(women, men and kids) and category (dress, tops, tees etc) they wish to see. For this am using check box. If user checks(selects) only women departments they all products which belongs to women will be displayed. If user checks(selects) both women department and dress category then the products which belongs to both women department and dress category will be displayed. If user selects both women and men departments and shoes category then all products which belongs to women and men department and shoes category will be displayed. To achieve this am using solr (sunspot gem). My question is can we pass multiple ids for department_id and category_id at the same time.

For example is it possible to

@search_res=ProductDetail.search do
  with :department_id, 1,2,3                  
  with :category_id, 1,2,3,4, etc (may be present or absent)           
end

If it is possible please tell me how to do? Please give me syntax? Please help me.

Update

Thank you Salil for your answer, but department id and category id's are not static in this case. I will came to only when user selects at runtime. Means category_id and department_id's are generic. How to achieve this. I want something like this

@search_res=ProductDetail.search do
  with :department_id, params[:deptid]                  
  with :category_id,   params[:catid]         
end

Please help me.

4

1 回答 1

1

这里是:

@search_res=ProductDetail.search do
  all_of do
    with :department_id, [1,2,3]                  
    with :category_id, [nil,1,2,3,4] # I am not sure - but category_id nil should be to denote its absence 
  end
end

参考更多信息: 太阳黑子自述文件

于 2012-06-05T06:13:24.247 回答