关系不会索引
我在为我的模型之一建立索引时遇到问题。
这是我的模型:
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>
任何人都知道为什么跟踪器
关系有效,但不知道源
?
我在 OS X 10.7 中使用 Sphinx 0.9.9-release、Rails 3.1.0.rc5。
更新
在使用此 rake 任务(重新索引而不是索引)时,我在索引部分没有收到任何错误。
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
使用 rakethinking_sphinx:rebuild
重新索引数据库,而不是 rakethinking_sphinx:index
和 rakethinking_sphinx:reindex
>。
I'm having some problem indexing one of my models.
Here is my model:
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
I'm running this to index the model:
rake thinking_sphinx:index --trace
Here is the error:
undefined method `priority' for #<ThinkingSphinx::Source:0x00000106ae1738>
Anyone knows why the tracker
relations works, but not the source
?
I'm using Sphinx 0.9.9-release, Rails 3.1.0.rc5 in OS X 10.7.
Update
I don't get any errors during the indexing-part when using this rake task (reindex instead of index).
rake thinking_sphinx:reindex
The problem is now that I can't use the priority field.
This is the code used when searching:
Model.search(with: {priority: [1]})
This line of code:
has source(:priority)
Results in this error:
ArgumentError: wrong number of arguments (1 for 0) # Produced by the line above.
Using this line:
has source.priority
Results in this error:
NoMethodError: undefined method `priority' for #<ThinkingSphinx::Source:0x00000106b0ff98>
Anyone knows why?
Update 2
Used rake thinking_sphinx:rebuild
to reindex the database, instead of rake thinking_sphinx:index
and rake thinking_sphinx:reindex
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如列表中所讨论的,您需要使用
assoc
方法来解决此问题:这里的问题是,在幕后,Sphinx 索引具有源 - 因此 Thinking Sphinx 会自动构建源,因此保留源方法。我真的应该改变这一点,但这同时可以帮助你解决这个问题。
As discussed on the list, you need to use the
assoc
method to work around this:The issue here is that under the hood, Sphinx indices have sources - and so Thinking Sphinx is constructing sources automatically, hence the reserved source method. I really should change that, but this will get you around it in the meantime.