使用 Sunspot 从 Solr 索引中排除草稿 [英] Exclude draft articles from Solr index with Sunspot

查看:35
本文介绍了使用 Sunspot 从 Solr 索引中排除草稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 Article 的索引模型,我不希望 solr 索引未发表的文章.

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

class Article < ActiveRecord::Base
  searchable do
    text :title
    text :body
  end
end

我怎样才能指定那篇文章不是#published?不应该被索引?

How can I specify that article that is not #published? should not be indexed?

推荐答案

请务必索引已发布的状态.

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

这篇关于使用 Sunspot 从 Solr 索引中排除草稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆