pat / thinking-sphinx

Sphinx/Manticore plugin for ActiveRecord/Rails
http://freelancing-gods.com/thinking-sphinx
MIT License
1.63k stars 469 forks source link

Undefined method `define_index' with Rails 3.2.2 #369

Closed virtualmice closed 11 years ago

virtualmice commented 12 years ago

Hi,

I'm stuck with a elusive problem and I have Goggled in vain for a usable piece of knowlege regarding it :

On top of my Gemfile is :

ource 'https://rubygems.org'

gem 'rails', '3.2.2'

# database
gem 'mysql2'

gem 'riddle', '~> 1.5.0'
gem 'thinking-sphinx', '~>2.0.12', :require => 'thinking_sphinx' # Only recent version will rune with Rails 3.2 !
#gem 'acts_as_indexed', '0.7.8'

N.B. I tried with AND without ":require => 'thinking_sphinx' "

define_index is only invoked in one sigle model :

class Question < ActiveRecord::Base
  # .../...
  define_index do
    indexes :text
    indexes :hint
    indexes propositions.text
  end
  # .../...
end

Failure occurs in TWO distinct contexts, rake AND in the app :

bundle exec rake ts:config --trace
rake aborted!
undefined method `define_index' for #<Class:0x96d23ac>
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/activerecord-3.2.2/lib/active_record/dynamic_matchers.rb:50:in `method_missing'
/home/virtualmice/Projects/triviasports-server/app/models/question.rb:35:in `<class:Question>'
/home/virtualmice/Projects/triviasports-server/app/models/question.rb:1:in `<top (required)>'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `block in require'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:251:in `require'
/home/virtualmice/Projects/triviasports-server/lib/tasks/dummy.rake:25:in `block (2 levels) in <top (required)>'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task_manager.rb:207:in `in_namespace'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/dsl_definition.rb:102:in `namespace'
/home/virtualmice/Projects/triviasports-server/lib/tasks/dummy.rake:23:in `block in <top (required)>'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/task_manager.rb:207:in `in_namespace'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/dsl_definition.rb:102:in `namespace'
/home/virtualmice/Projects/triviasports-server/lib/tasks/dummy.rake:1:in `<top (required)>'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `block in load'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/railties-3.2.2/lib/rails/engine.rb:425:in `block in load_tasks'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/railties-3.2.2/lib/rails/engine.rb:425:in `each'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/railties-3.2.2/lib/rails/engine.rb:425:in `load_tasks'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/railties-3.2.2/lib/rails/application.rb:145:in `load_tasks'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@triviasports/gems/railties-3.2.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/virtualmice/Projects/triviasports-server/Rakefile:7:in `<top (required)>'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `load'
/home/virtualmice/.rvm/gems/ruby-1.9.3-p194@global/bin/rake:19:in `<main>'

In the app a stange bug occur : STI overrides of some methods seem to disapear ?!

Actually, it veru much looks as if TS was figthting with STI. Is that possible ?

Trying to wrap my index definition in a module and inject it in child classes produces a STI-related error :

The single-table inheritance mechanism failed to locate the subclass: 'UniqueMcq'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Question.inheritance_column to use another column for that information.

Is a conflict over a 'type' attribute or method a possibility ?

Thanks for any hint at some solution, I'm pretty stuck.

pat commented 12 years ago

STI certainly can cause problems... though I'd be expecting something else is going wrong somewhere. What's in your dummy.rake file? I wonder if that's doing something before the Rails environment is fully loaded?

virtualmice commented 12 years ago

The dummy.rake (28) ist just require-ing the incriminated STI Question model

require File.join( File.dirname(__FILE__), '../..', 'app', 'models', 'question' )
pat commented 12 years ago

What happens if you comment that line out? Why not let Rails load things the way it expects?

virtualmice commented 12 years ago

Anyway STI seems to me a bad coding practice. It's just that many existing projects happen to use it.

virtualmice commented 12 years ago

Can't test it right now, I discarded the branch.

I think the require was already a desperate attempt at making it work.

pat commented 12 years ago

Okay... well, if that require wasn't helping, am curious what the stack trace is now...

virtualmice commented 12 years ago

Well, sorry about that, deadline imposed postponing TS integration. I'll sure let you know as soon as as give it another try.

I wonder how many people are currently using Rails 3.2.2 with TS and other popular gems. I've had problems with acts_as_taggable_on too.

At this point I don't know if it's me being clumsy or if there is some real gem breakage with 3.2.2 :-/

pat commented 12 years ago

No worries. If you get another chance to look into it, let me know.

On 27/07/2012, at 17:50, Philippe Lachaise reply@reply.github.com wrote:

Well, sorry about that, deadline imposed postponing TS integration. I'll sure let you know as soon as as give it another try.


Reply to this email directly or view it on GitHub: https://github.com/freelancing-god/thinking-sphinx/issues/369#issuecomment-7308788

kakubei commented 12 years ago

Hello, I'm having the same issue but with Padrino 0.10.7 and thinking-sphinx 2.0.13 without Rails.

I have this in my Gemfile:

gem 'thinking-sphinx',  '~> 2.0.13'

And simply trying to start the app with config.ru I get the error:

`method_missing': undefined method `define_index' for #Class...

Is there anything else needed to use thinking sphinx with Padrino and no Rails?

Thanks.

PS Maybe I should open a new issue with the proper title Padrino so as not to confuse this one?