【问题标题】:Thinking Sphinx with Rails - Delta indexing seems to work fine for one model but not for the otherThinking Sphinx with Rails - Delta 索引似乎适用于一种模型,但不适用于另一种模型
【发布时间】:2010-04-08 22:32:03
【问题描述】:

我有 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

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

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

def set_user_delta_flag
user.delta = true
user.save
end

即使这似乎也不会触发用户模型上的增量索引。讨论模型的类似设置完美运行!谁能告诉我为什么会这样?

【问题讨论】:

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


    【解决方案1】:

    好吧,我想通了。问题出在属性定义上:

    has user(:id)
    

    当我从定义中删除它并运行重建时,一切似乎都运行良好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-21
      • 1970-01-01
      • 1970-01-01
      • 2019-11-16
      • 1970-01-01
      相关资源
      最近更新 更多