【发布时间】:2014-11-07 11:29:40
【问题描述】:
我有一个包含 2 个关联“内容”和“订阅”的频道模型。
在频道索引中,用户可以按订阅数量或批准的内容数量对频道进行排序。
虽然在开发过程中一切似乎都正常运行(通过观察结果,可能会出现故障并且是没有足够的数据来正确查看的问题),但在暂存时,结果是随机的,有时会正确显示,有时不会' t.
起初我没有使用增量索引,并认为问题可能存在,所以每次我批准我调用的内容时:
Delayed::Job.enqueue(DelayedRake.new("ts:index"), queue: "sphinx")
由于订阅没有索引,我不会在每次创建时重新索引(我应该这样做吗?)
然后我开始在通道中使用增量索引,但我仍然遇到同样的问题:
ThinkingSphinx::Index.define :channel, with: :active_record, delta: true do
# fields
indexes :name, sortable: true
indexes description
# attributes
has created_at, sortable: true
has approved, type: :boolean
has public, type: :boolean
join subscriptions
has "COUNT(subscriptions.id)", as: :subscription_count, type: :integer, sortable: true
join contents.approved
has "COUNT(contents.id)", as: :content_count, type: :integer, sortable: true
end
这是控制器中的搜索调用:
def index
if params[:order_by].present?
@channels = Channel.search params[:search],
order: "#{params[:order_by]} DESC",
page: params[:page], per_page: 6
else
@channels = Channel.search params[:search],
order: :name,
page: params[:page], per_page: 6
end
end
总结一下,我的问题是: 1. 我的频道索引是否正确? 2. 订阅也应该被编入索引还是将它们加入我的频道索引就足够了? 3. 我应该在创建订阅/批准内容后运行 reindex,还是通道中的增量索引处理该问题,因为我将这两个控制器加入了通道索引?
【问题讨论】:
标签: ruby-on-rails-4 thinking-sphinx