致命:在配置文件中找不到索引' /mathath/config/development.sphinx.conf'

时间:2014-07-23 17:03:01

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

所以,我在制作中使用Thinking Sphinx和heroku加载项Flying Sphinx

但是,我似乎得到了以下错误

using config file '/mypath/config/development.sphinx.conf'...
FATAL: no indexes found in config file '/mypath/config/development.sphinx.conf'

我已经阅读过其他一些SO帖子,但没有一个有助于解决我的问题,更具体地说,我使用的是act_as_taggable gem并且标签没有被编入索引,但其他所有内容都被编入索引很好。

ThinkingSphinx::Index.define :clip, :with => :real_time do
  # fields
  indexes :name
  indexes sort_name, :sortable => true
  indexes description
  indexes taggings.tag.name, :as => :tags
end

我猜测它是因为标记是一种关联,这导致了一些问题。

我做错了什么?

谢谢!

1 个答案:

答案 0 :(得分:1)

通过GitHub问题解决了这个问题,但在此重新进行了迭代:

实时索引中字段/属性的方法链必须与您自己在应用中调用的方法链完全相同 - 因此,taggings.tag.name无效。实际上,在剪辑的上下文中,您想要的是以下内容:

clip.taggings.collect(&:tag).collect(&:name)

但是,这不能在Thinking Sphinx索引中应用,因为它只允许使用 no 参数的方法。解决方法是在模型中定义一个方法,该方法返回这些标记名称的单个字符串值:

def tag_names
  taggings.collect(&:tag).collect(&:name).join(' ')
end

然后在索引定义中使用它:

indexes tag_names, :as => :tags

现在,您已经更改了索引定义,因此您需要运行rake ts:regenerate rake任务,因为您正在使用实时索引。您的问题从索引输出开始,ts:index任务仅适用于SQL支持的索引,而不适用于实时索引,因此请确保在更改索引结构时使用ts:regeneratets:generate如果您的Sphinx数据不是最新的(例如,如果在更改数据时未触发回调)。