rake ts:配置rake ts:index thinking-sphinx-3.1.1 ruby​​-2.0.0错误

时间:2014-08-19 08:21:28

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

我正在尝试在我的localhost上配置运行应用程序的rails。我之前没有使用过狮身人面像。我在我的Ubuntu机器上安装了sphinx-search并且它的服务正在运行。

当我尝试执行rake ts:index或rake ts:configure时出现以下错误:

NoMethodError: undefined method `klass' for nil:NilClass

这是完整的堆栈跟踪:

rake ts:configure --trace
** Invoke ts:configure (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute ts:configure
Generating configuration to /home/baran/code/atdhe/config/development.sphinx.conf
rake aborted!
NoMethodError: undefined method `klass' for nil:NilClass
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib        

/thinking_sphinx/active_record/attribute/type.rb:37:in `block in associations'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib    
/thinking_sphinx/active_record/attribute/type.rb:35:in `collect'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib                    /thinking_sphinx/active_record/attribute/type.rb:35:in `associations'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/attribute/type.rb:62:in `multi_from_associations'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib    /thinking_sphinx/active_record/attribute/type.rb:9:in `multi?'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/attribute.rb:4:in `multi?'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/attribute/sphinx_presenter.rb:18:in `collection_type'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:96:in `block in append_presenter_to_attribute_array'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:93:in `each'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:93:in `append_presenter_to_attribute_array'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:132:in `prepare_for_render'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/sql_source.rb:65:in `render'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/riddle-1.5.11/lib/riddle/configuration/index.rb:29:in `block in render'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/riddle-1.5.11/lib/riddle/configuration/index.rb:29:in `collect'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/riddle-1.5.11/lib/riddle/configuration/index.rb:29:in `render'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/core/index.rb:53:in `render'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/riddle-1.5.11/lib/riddle/configuration.rb:43:in `block in render'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/riddle-1.5.11/lib/riddle/configuration.rb:43:in `collect'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/riddle-1.5.11/lib/riddle/configuration.rb:43:in `render'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:90:in `render'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `block in render_to_file'
/home/baran/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/open-uri.rb:36:in `open'
/home/baran/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/open-uri.rb:36:in `open'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `render_to_file'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/rake_interface.rb:13:in `configure'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/tasks.rb:4:in `block (2 levels) in <top (required)>'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/task.rb:240:in `call'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/task.rb:240:in `block in execute'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/task.rb:235:in `each'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/task.rb:235:in `execute'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/baran/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/task.rb:165:in `invoke'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/application.rb:150:in `invoke_task'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/application.rb:106:in `each'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/application.rb:106:in `block in top_level'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/application.rb:115:in `run_with_threads'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/application.rb:100:in `top_level'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/application.rb:78:in `block in run'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/lib/rake/application.rb:75:in `run'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/gems/rake-10.3.2/bin/rake:33:in `<top (required)>'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/bin/rake:23:in `load'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/bin/rake:23:in `<main>'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/bin/ruby_executable_hooks:15:in `eval'
/home/baran/.rvm/gems/ruby-2.0.0-p481@athde/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => ts:configure

以下是索引文件:

ThinkingSphinx::Index.define :restaurant, :with => :active_record, :delta =>    ThinkingSphinx::Deltas::DelayedDelta do

  indexes school(:school_name), :sortable => true, :as => :school_name
  indexes school(:branch_name), :sortable => true, :as => :branch_name
  indexes school(:delta) => ThinkingSphinx::Deltas::DelayedDelta
  has restaurant_info(:is_pick_up), :as => :pick_up, :facet => true
  has delivery_info(:is_delivery),  :as => :delivery, :facet => true

  indexes contact_info(:restaurant_name), :sortable => true

  indexes delivery_info(:delivery_charges), :as => :delivery_charges

  has school(:id), :as => :school_id, :facet => true

  has restaurant_categories(:id), :as => :restaurant_category_ids, :facet => true

  has restaurant_info(:min_order), :as => :min_order, :type => :float, :sortable => true

  has avg_rating, :as => :rating, :type => :integer, :sortable => true
  has ranking, :as => :ranking, :type => :integer, :sortable => true

  has delivery_info(:delivery_estimated_time), :as => :delivery_eta, :type => :integer, :sortable => true

      set_property :min_infix_len => 1
  set_property :delta => ThinkingSphinx::Deltas::DelayedDelta
end


ThinkingSphinx::Index.define :school, :with => :active_record, :delta =>         ThinkingSphinx::Deltas::DelayedDelta do
  indexes :school_name, :sortable => true, :as => :school_name
  indexes buildings(:building_name), :sortable => true
  set_property :min_infix_len => 1
  set_property :delta => ThinkingSphinx::Deltas::DelayedDelta
end

1 个答案:

答案 0 :(得分:0)

您的索引稍作清理:

ThinkingSphinx::Index.define :restaurant, :with => :active_record, :delta => ThinkingSphinx::Deltas::DelayedDelta do

  indexes school.school_name, :sortable => true, :as => :school_name
  indexes school.branch_name, :sortable => true, :as => :branch_name
  indexes contact_info.restaurant_name, :sortable => true, :as => :restaurant_name
  indexes delivery_info.delivery_charges, :as => :delivery_charges

  has restaurant_info.is_pick_up, :as => :pick_up, :facet => true
  has delivery_info.is_delivery,  :as => :delivery, :facet => true
  has school.id, :as => :school_id, :facet => true

  has restaurant_categories.id, :as => :restaurant_category_ids, :facet => true
  has restaurant_info.min_order, :as => :min_order, :type => :float

  has avg_rating, :as => :rating, :type => :integer
  has ranking, :as => :ranking, :type => :integer

  has delivery_info.delivery_estimated_time, :as => :delivery_eta, :type => :integer

  set_property :min_infix_len => 1
end

ThinkingSphinx::Index.define :school, :with => :active_record, :delta => ThinkingSphinx::Deltas::DelayedDelta do
  indexes school_name, :sortable => true, :as => :school_name
  indexes buildings.building_name, :as => :building_name, :sortable => true

  set_property :min_infix_len => 1
end

我所做的改变:

  • :sortable => true已从属性中删除(has次调用)。属性可以按其性质进行排序,因此该选项不会改变任何内容。
  • 删除了针对增量的set_property调用 - 这是在TS v3之后的索引顶部完成的(正如您已经在做的那样)。
  • 删除了引用delta列的字段,该字段看起来有点像delta设置。
  • 将列调用更改为符号/方法参数作为方法名称 - 您使用的是Ruby 1.8所需要的,但现在不需要(并且可能有错误)使用TS v3和Ruby 1.9或更新版本。
  • 确保通过关联引用列的所有字段和属性都具有自定义名称(:as选项)。

还值得注意的是,如果要使用的列是那些类型,则不需要为属性指定类型。因此,如果avg_rating 是整数,那么您不需要该属性的:type => :integer选项。

我的猜测是字段/增量设置的组合是问题的主要原因,但是给它一个旋转,看看是否有帮助。