Sunspot with multiple models (in Rails)

前端 未结 1 1531
北恋
北恋 2021-01-31 21:31

I have three models (User, Tag, Product) and they interact s.t. User has many Tags and Products.

相关标签:
1条回答
  • 2021-01-31 22:01

    I like the idea of a Search object if you are doing any complicated conditions.

    But to search across objects using Sunspot:

    @sunspot_search = Sunspot.search User, Tag, Product do |query| 
      query.keywords @search_query
      query.with(:age).greater_than 20
      query.with(:age).less_than 25
      query.paginate(:page => params[:page], :per_page => 30)
    end
    
    0 讨论(0)
提交回复
热议问题