首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义的方法`define_index‘with sphinx sphinx

未定义的方法`define_index‘with sphinx sphinx
EN

Stack Overflow用户
提问于 2013-05-13 02:19:48
回答 1查看 2K关注 0票数 0

当我运行rake ts:index或rake ts:configure时得到这个错误。我记不住我尝试过的所有东西--我找到的大多数解决方案都与旧版本的gem有关,等等。显然,这不是我的define_index定义,我把它放在了索引文件夹中,这是最新的想法-sphinx自述文件。

代码语言:javascript
复制
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

index.rb/item_index.rb

代码语言:javascript
复制
ThinkingSphinx::Index.define :item, :with => :active_record do
  indexes name
  indexes ftype
  indexes description
end

items_controller.rb

代码语言:javascript
复制
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

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-13 03:15:07

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16510613

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档