太阳黑子轨道搜索,拒绝按条件创建构面

时间:2013-02-25 12:04:00

标签: sunspot faceted-search sunspot-rails sunspot-solr facets

我在Ruby on Rails中使用sunspot_rails gem进行全文搜索,
我在我的模型产品中添加了布尔字段(' show_facet'), 和solr指数
然后我想做下一步:

  • 如果' show_facet' == true然后在搜索列表和构面列表中显示产品
  • 如果' show_facet' == false然后仅在搜索列表中显示产品

我阅读了所有文档,论坛和API,但我找不到这个问题的答案
我可以用太阳黑子做这个吗?

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

我需要在facet(:keywords)中包含show_facet = true的产品中的facet,但是在搜索中显示所有产品(show_facet为true或false)

0 个答案:

没有答案