关系不会索引

时间:2011-08-14 17:08:30

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

我在为我的某个模型编制索引时遇到了一些问题。

这是我的模特:

class Model < ActiveRecord::Base
  define_index do
    # ...
    has tracker.open, as: :open, type: :boolean
    has source.priority, as: :priority, type: :integer
    # ...
  end

  belongs_to :tracker
  belongs_to :source
end

我正在运行它来索引模型:

rake thinking_sphinx:index --trace

这是错误:

undefined method `priority' for #<ThinkingSphinx::Source:0x00000106ae1738>

任何人都知道为什么tracker关系有效,而不是source? 我在OS X 10.7中使用Sphinx 0.9.9发行版,Rails 3.1.0.rc5。

更新

在使用此rake任务( reindex 而非 index )时,我在索引部分期间没有出现任何错误。

rake thinking_sphinx:reindex

问题是我现在无法使用优先级字段。 这是搜索时使用的代码:

Model.search(with: {priority: [1]})

这行代码:

has source(:priority)

导致此错误:

ArgumentError: wrong number of arguments (1 for 0) # Produced by the line above.

使用此行:

has source.priority

导致此错误:

NoMethodError: undefined method `priority' for #<ThinkingSphinx::Source:0x00000106b0ff98>

任何人都知道为什么?

更新2

使用rake thinking_sphinx:rebuild重新编制数据库索引,而不是rake thinking_sphinx:indexrake thinking_sphinx:reindex

1 个答案:

答案 0 :(得分:1)

正如列表中所讨论的,您需要使用assoc方法解决此问题:

has assoc(:source).priority

这里的问题在于,Sphinx索引有源 - 所以Thinking Sphinx自动构建源,因此保留源方法。我真的应该改变这一点,但这会让你在此期间解决它。

相关问题