未定义的方法`define_index'与思考 - 狮身人面像

时间:2013-05-12 18:19:48

标签: ruby-on-rails ruby indexing thinking-sphinx configure

运行rake ts:index或rake ts:configure时出现此错误。我记不起我所尝试过的所有内容 - 我发现的大多数解决方案都与旧版本的宝石等有关。显然,这不是我的define_index定义,我按照最新思维 - sphinx的指示将其放在indices文件夹中自述。

Generating configuration to /Users/Eamon/projectsgmb/gmb/config/development.sphinx.conf
rake aborted!
undefined method `define_index' for #<Class:0x007ffba4e51120>
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activerecord-3.2.13/lib/active_record/dynamic_matchers.rb:55:in `method_missing'
/Users/Eamon/projectsgmb/gmb/app/models/item.rb:4:in `<class:Item>'
/Users/Eamon/projectsgmb/gmb/app/models/item.rb:1:in `<top (required)>'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:469:in `load'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:469:in `block in load_file'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:639:in `new_constants_in'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:468:in `load_file'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:353:in `require_or_load'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:502:in `load_missing_constant'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:192:in `block in const_missing'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:190:in `each'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:190:in `const_missing'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:230:in `block in constantize'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:229:in `each'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/inflector/methods.rb:229:in `constantize'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/activesupport-3.2.13/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/core/index.rb:40:in `model'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/active_record/index.rb:9:in `append_source'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/active_record/interpreter.rb:56:in `__source'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/active_record/interpreter.rb:20:in `indexes'
/Users/Eamon/projectsgmb/gmb/app/indices/item_index.rb:2:in `block in <top (required)>'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/core/interpreter.rb:3:in `translate!'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/core/index.rb:36:in `interpret_definition!'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/active_record/index.rb:28:in `sources'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration/consistent_ids.rb:31:in `collect'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration/consistent_ids.rb:31:in `sources'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration/consistent_ids.rb:19:in `attributes'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration/consistent_ids.rb:23:in `sphinx_internal_ids'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration/consistent_ids.rb:7:in `reconcile'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration.rb:76:in `render'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration.rb:84:in `block in render_to_file'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration.rb:84:in `open'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/configuration.rb:84:in `render_to_file'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/rake_interface.rb:4:in `configure'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/rake_interface.rb:31:in `index'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/gems/thinking-sphinx-3.0.3/lib/thinking_sphinx/tasks.rb:9:in `block (2 levels) in <top (required)>'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0@global/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval'
/Users/Eamon/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => ts:index

指数/ item_index.rb

ThinkingSphinx::Index.define :item, :with => :active_record do
  indexes name
  indexes ftype
  indexes description
end

items_controller.rb

class ItemsController < ApplicationController
  require 'thinking_sphinx'

  ...      

  def index
    @items = Item.search params[:search]

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @items }
    end
  end

  ...

end

item.rb的

class Item < ActiveRecord::Base
  attr_accessible :description, :ftype, :name

  define_index do
    indexes name
    indexes ftype
    indexes description

    has created_at, updated_at
  end

  validates :name, presence: true, length: { maximum: 50 }
  validates :ftype, presence: true, length: { maximum: 50 }
  validates :description, presence: true, length: { maximum: 100 }
end

1 个答案:

答案 0 :(得分:2)

define_index方法在Thinking Sphinx版本3.0.0之前使用。现在索引定义使用ThinkingSphinx::Index.define方法并驻留在app/indices/文件夹而不是模型文件中。实际上,您已经有了新式定义,因此您只需从define_index删除item.rb代码块。