Exclude draft articles from Solr index with Sunspot

前端 未结 3 1771

I have an indexed model called Article and I don\'t want solr to index unpublished articles.

class Article < ActiveRecord::Base
  searchable do
    text :         


        
3条回答
  •  日久生厌
    2021-01-13 22:44

    Be sure to index the published status.

    class Article < ActiveRecord::Base
      searchable do
        text :title
        text :body
        boolean :is_published, :using => :published?
      end
    end
    

    Then add a filter to your query

    Sunspot.search(Article) do |search|
      search.with(:is_published, true)
      # ...
    end
    

提交回复
热议问题