开发者

Thinking Sphinx with Rails - Delta indexing seems to work fine for one model but not for the other

开发者 https://www.devze.com 2022-12-25 23:00 出处:网络
I have 2 models User and Discussion. I have defined the indices for the models as below: For the User model:

I have 2 models User and Discussion. I have defined the indices for the models as below:

For the User model:

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

For the Discussion model:

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

I have added a de开发者_JAVA百科lta column to both tables as per the documentation. My problem is that delta indexing works only for the Discussion model and not for the User model. For ex: When I update the 'title' of a discussion, I can see the thinking sphinx is rotating the indices etc. (as is evident from the logs). But when I update the 'first_name' or the 'last_name' of a user, nothing happens.

The User model also has a has_many :through association through a model called GroupsUser. I have setup a after_save on the GroupsUser as follows:

def set_user_delta_flag
user.delta = true
user.save
end

Even this doesn't seem to trigger delta indexing on the User model. A similar setup for the Discussion model works perfectly! Can anyone tell me why this is happening?


Alright I figured it out. The problem was with the attribute definition:

has user(:id)

When I removed it from the definition and ran a rebuild, everything seemed to work perfectly.

0

精彩评论

暂无评论...
验证码 换一张
取 消