我需要索引这些关联:
Author has_many :contributions
Author has_many :books, through: :contributions
我试着把我的索引写成:
ThinkingSphinx::Index.define :author, :with => :active_record do
indexes books(:title), as: :book
end
但它无意工作。任何想法?
修改
当我尝试这个,或几乎所有其他解决方案后,我在rake ts:index:
之后得到了这个错误Generating configuration to /Users/Kuba/Desktop/Rails/black/config/development.sphinx.conf
rake aborted!
undefined method `active_record' for #<ActiveRecord::Associations::JoinDependency:0x007faa3d1e5070>
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/associations.rb:78:in `reflection_for'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/associations.rb:50:in `join_for'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/associations.rb:38:in `model_for'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:42:in `column_exists?'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:48:in `column_with_table'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:55:in `block in columns_with_table'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:54:in `collect'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:54:in `columns_with_table'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:31:in `casted_column_with_table'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/property_sql_presenter.rb:15:in `to_select'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/sql_builder.rb:127:in `collect'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/sql_builder.rb:127:in `select_clause'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/sql_builder.rb:10:in `sql_query'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/sql_source.rb:120:in `prepare_for_render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/active_record/sql_source.rb:62:in `render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.8/lib/riddle/configuration/index.rb:29:in `block in render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.8/lib/riddle/configuration/index.rb:29:in `collect'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.8/lib/riddle/configuration/index.rb:29:in `render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/core/index.rb:53:in `render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.8/lib/riddle/configuration.rb:39:in `block in render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.8/lib/riddle/configuration.rb:39:in `collect'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/gems/riddle-1.5.8/lib/riddle/configuration.rb:39:in `render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/configuration.rb:78:in `render'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/configuration.rb:84:in `block in render_to_file'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/configuration.rb:84:in `render_to_file'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/rake_interface.rb:4:in `configure'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/rake_interface.rb:31:in `index'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bundler/gems/thinking-sphinx-ec658bff0479/lib/thinking_sphinx/tasks.rb:9:in `block (2 levels) in <top (required)>'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval'
/Users/Kuba/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => ts:index
(See full trace by running task with --trace)
答案 0 :(得分:1)
试试这个,
ThinkingSphinx::Index.define :author, :with => :active_record do
indexes books.title, :as => :title
end
修改强>
请在git中检查此问题。 https://github.com/pat/thinking-sphinx/issues/517