I use sunspot_rails gem in full text searching in Ruby on Rails,
I added boolean field ('show_facet') to my model Product,
and to solr index
Then I want to do next:
- if 'show_facet' == true then show Product in search list and facets list
- if 'show_facet' == false then show Product only in search list
I read all docs, forums and api but I can't find answer to this question
Could I do this with sunspot?
Model Code searchable do string :keywords, multiple: true string :status boolean :show boolean :show_facet time :updated_at text :keyword_long, stored: true text :jtitle, stored: true integer :id integer :company_id end Controller def show @product_search = OpenStruct.new(params[:product_search]) @search = search_plain end private def search_plain basic_search do |search| search.fulltext(@product_search.fulltext) do fields *(%w[jtitle keyword_long]) highlight :keyword_long highlight :jtitle end end end def basic_search Product.solr_search do |search| yield search search.with(:show, true) search.order_by(:random) search.paginate page: params[:page], per_page: 10 search.with(:keywords).all_of(@product_search.keywords) search.facet :keywords end end
I need include in facet(:keywords) only facets from product with show_facet = true, but show all products in search (with show_facet true or false)