使用Rails思考Sphinx - Delta索引似乎适用于一个模型但不适用于另一个模型

时间:2010-04-08 22:32:03

标签: ruby-on-rails indexing thinking-sphinx delta

我有2个模型用户和讨论。我已经为模型定义了如下指数:
对于用户模型:

define_index do
indexes email
indexes first_name
indexes last_name, :sortable => true
indexes groups(:name), :as => :group_names
has "IF(email_confirmed = true and status = 'approved', true, false)", :as => :approved_user, :type => :boolean
has "IF(email_confirmed = true and (status = 'approved' or status='blocked'), true, false)", :as => :approved_or_blocked_user, :type => :boolean
has points, :type => :integer
has created_at, :type => :datetime
has user(:id)
set_property :delta => true
end

对于讨论模型:

define_index do
indexes title
indexes description
indexes category(:title), :as => :category_title
indexes tags(:title), :as => :tag_title
has "IF(publish_to_blog = true AND sticky = false, true, false)", :as => :publish_to_main, :type => :boolean
has created_at
has updated_at, :type => :datetime
has recent_activity_at, :type => :datetime
has views_count, :type => :integer
has featured
has publish_to_blog
has sticky
set_property :delta => true
end

我已根据文档向两个表添加了一个增量列。我的问题是delta索引仅适用于Discussion模型而不适用于User模型。例如:当我更新讨论的“标题”时,我可以看到思维狮身人面像正在旋转索引等(从日志中可以看出)。但是当我更新用户的'first_name'或'last_name'时,没有任何反应。

User模型还有一个has_many:通过名为GroupsUser的模型进行关联。我在GroupsUser上设置了一个after_save,如下所示:

def set_user_delta_flag
user.delta = true
user.save
end

即使这似乎也没有触发User模型上的delta索引。 Discussion模型的类似设置完美无缺!谁能告诉我为什么会这样?

1 个答案:

答案 0 :(得分:0)

好吧我明白了。问题在于属性定义:

has user(:id)

当我从定义中删除它并运行重建时,一切似乎都完美无缺。