mysql - RoR - rake rs :index fails with NameError on Rails 4. 0.4(4.1.7),思考狮身人面像 3.1.1

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

我尝试为 sphinx 搜索引擎索引我的 mysql 数据库,这就是我得到的结果。我浏览了整个 stackoverflow,降级了我的 Rails,更新了 sphinx 和 ts 大约 5 到 6 次。我仔细检查了我的代码(也许问题就在那里)。我贬低了 config.threadsafe!以及其他任何事情,它仍然根本不起作用。或许你可以帮我。以下是控制台日志和部分原始代码:

pchudinov:xxx chud$ rake ts:index
/Library/Ruby/Gems/2.0.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:222: warning: Insecure world writable dir /usr/local in PATH, mode 040777
DEPRECATION WARNING: config.threadsafe! is deprecated. Rails applications behave by default as thread safe in production as long as config.cache_classes and config.eager_load are set to true. (called from <class:Application> at /xxx/config/application.rb:29)
searchd is not currently running.
Stopped searchd daemon (pid: ).
Generating configuration to /xxx/config/development.sphinx.conf
rake aborted!
NameError: uninitialized constant RealTeams
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `const_get'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `block in constantize'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `each'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `inject'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `constantize'
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.0.2/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/core/index.rb:43:in `model'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/index.rb:9:in `append_source'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/interpreter.rb:63:in `__source'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/interpreter.rb:20:in `indexes'
/xxx/app/indices/real_teams_index.rb:2:in `block in <top (required)>'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/core/interpreter.rb:3:in `translate!'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/core/index.rb:39:in `interpret_definition!'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/index.rb:32:in `sources'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:31:in `collect'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:31:in `sources'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:19:in `attributes'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:23:in `sphinx_internal_ids'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:7:in `reconcile'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:87:in `render'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `block in render_to_file'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `open'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `render_to_file'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/rake_interface.rb:13:in `configure'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/rake_interface.rb:24:in `index'
/Library/Ruby/Gems/2.0.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/tasks.rb:9:in `block (2 levels) in <top (required)>'
Tasks: TOP => ts:index
(See full trace by running task with --trace)

以下是“RealTeam”的原始代码:

Controller :

  def search
      @real_teams = RealTeam.search params[:search]
  end

型号:

class RealTeam < ActiveRecord::Base
  has_many :players
  has_many :home_matches, :class_name => 'Match', :foreign_key => 'team_home_id'
  has_many :away_matches, :class_name => 'Match', :foreign_key => 'team_away_id'
  has_many :performances
end

索引:

ThinkingSphinx::Index.define :real_teams, :with => :active_record do
    indexes :name
end

附注我对 Rails 还不太熟悉,但据我认为代码做得很好。

最佳答案

您的索引定义应引用 :real_team(单数,如模型名称)而不是 :real_teams

关于mysql - RoR - rake rs :index fails with NameError on Rails 4. 0.4(4.1.7),思考狮身人面像 3.1.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26734975/

相关文章:

mysql - 单个sql语句在innodb中总是原子的吗?

c++ - 为什么 "SHOW PROCESSLIST"不给 Host IP?

mysql - 将子查询转换为 INNER JOIN

python - django 会在接下来的 ~5~ 年内存在吗?

php - 使用 PHP 向 MySQL 数据库中插入数据时出错

javascript - 输入总和问题

ruby-on-rails - 载波 uploader 的未定义方法过程

ruby - Nokogiri:用 <p> 标签包裹顶级文本元素

ruby - Encoding::BINARY 和 Encoding::ASCII-8BIT 之间的区别?

没有 `each` 的 ruby 哈希迭代