pat / thinking-sphinx

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

NoMethodError: undefined method `constantize' for 0:Fixnum #268

Closed pabloalr closed 13 years ago

pabloalr commented 13 years ago

This bug only happens in production, I was unable to reproduce it in development mode.

Using ThinkingSphinx 2.0.5 and Riddle 1.4.0.

The framework backtrace blame search.rb on line 913

[GEM_ROOT]/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/search.rb:913:in `class_from_crc'
[GEM_ROOT]/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/search.rb:892:in `block in instances_from_matches'
[GEM_ROOT]/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/search.rb:890:in `each'
[GEM_ROOT]/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/search.rb:890:in `instances_from_matches'
[GEM_ROOT]/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/search.rb:423:in `compose_results'
[GEM_ROOT]/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/search.rb:413:in `block in populate'
[GEM_ROOT]/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/search.rb:551:in `call'
[GEM_ROOT]/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/search.rb:551:in `retry_on_stale_index'
[GEM_ROOT]/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/search.rb:394:in `populate'
[GEM_ROOT]/gems/thinking-sphinx-2.0.5/lib/thinking_sphinx/search.rb:176:in `method_missing'

My index (the relevant part...):

class Thing < ActiveRecord::Base
  belongs_to :owner
  ...
  define_index
    ...
    has owner(:id), :as => :owner_id
    ...
  end
end

And my search call...

ThinkingSphinx.search(params[:term],
                                    :sort_mode => :expr,
                                    :order => '@weight',
                                    :with => { :owner_id => current_owner.id }
                                   )

Switched back to 2.0.4 and everything is ok.

pat commented 13 years ago

Are any of the models you've indexed involved in STI setups? I'm wondering if one of your type columns has NULL values (which Sphinx translates to 0's), instead of the base type.

pabloalr commented 13 years ago

No STI or polymorphism involved. I forgot to mention, the belongs_to have a counter_cache..

  ...
  belongs_to :owner, :counter_cache => true
  ...
pat commented 13 years ago

Okay, I guessed wrong... What version of Sphinx are you using on production, and has that changed recently?

pabloalr commented 13 years ago

Hi there. I'm running Ruby 1.9.2p180 and Sphinx 2.0.1-beta... everything was working well until I switched to TS 2.0.5.

pat commented 13 years ago

TS 2.0.5 changes the way classes for search results are tracked with Sphinx 2.0.1 - did you run rake ts:rebuild after upgrading Thinking Sphinx?

pat commented 13 years ago

(And yes, this isn't documented - so it's my fault).

pabloalr commented 13 years ago

Yep, Capistrano do a rebuild on every deploy...

pat commented 13 years ago

I'm not doing pretty well at guessing the cause of this, I'm afraid. Does using edge TS (rails3 branch) work instead of 2.0.5?

pabloalr commented 13 years ago

Good question! I'm unable to switch right now since I have some users using it, but as soon as possible I'll test it.

It's a very odd behaviour that only happens on production mode... the only difference, besides the production mode, is the server I'm using... nginx instead of Webrick, but I don't think this can influence at all.

On Wed, Aug 17, 2011 at 10:05 AM, freelancing-god < reply@reply.github.com>wrote:

I'm not doing pretty well at guessing the cause of this, I'm afraid. Does using edge TS (rails3 branch) work instead of 2.0.5?

Reply to this email directly or view it on GitHub:

https://github.com/freelancing-god/thinking-sphinx/issues/268#issuecomment-1826103

pat commented 13 years ago

I've used TS and Sphinx with nginx before, and I know plenty of others do as well, so I very much doubt that's the cause. When you do retry and if the problem still occurs, can you run the following and let me know what the result is?

ThinkingSphinx.search_for_ids(params[:term],
  :sort_mode => :expr,
  :order => '@weight',
  :with => { :owner_id => current_owner.id }
).results[:matches]
pabloalr commented 13 years ago

Just switched to ts rails3 branch, got the same problem, only when in production mode...

Here goes the output. Please note that the 'owner_id' is actually 'company_id'... I kind of used a pseudo-code on my examples to obfuscate things... :) but the rules are the same, it isn't a polymorphic or STI.

ruby-1.9.2-p180 :006 > ThinkingSphinx.search_for_ids('cassia', 
                                    :sort_mode => :expr, 
                                    :order => '@weight', 
                                    :with => {:company_id => 2}).results[:matches]
=> [{:doc=>669, :weight=>2, :index=>0, :attributes=>{"sphinx_internal_id"=>334, 
"sphinx_deleted"=>0, "class_crc"=>1921285768, "sphinx_internal_class"=>0,
"created_at"=>1308855477, "updated_at"=>1310663245,
"company_id"=>2, "@expr"=>2.0}}, {:doc=>544, :weight=>1, :index=>1, 
:attributes=>{"sphinx_internal_id"=>272, "sphinx_deleted"=>0, 
"class_crc"=>2212487076, "sphinx_internal_class"=>0, "created_at"=>1313005564, 
"updated_at"=>1313005594, "company_id"=>2, "@expr"=>1.0}}]
pat commented 13 years ago

Are you sure you're using Sphinx 2.0.1? The attributes returned don't match what I'm expecting. Do you have anything in your config/sphinx.yml file?

pabloalr commented 13 years ago

Yep, Sphinx 2.0.1-beta(r2792).

My config/sphinx.yml only have path for searchd

pat commented 13 years ago

So I'm going back to my original guess - do you have a type column?

pat commented 13 years ago

To explain further - if there's a type column, TS presumes you're using it like Rails does, for STI inheritance, and so sphinx_internal_class uses it to determine the class for search results. It's being returned as 0 in both of the examples above, which means the type column probably exists but is NULL.

pabloalr commented 13 years ago

Hi. Sorry the delay...

So, I guess this error should occur also in development mode, right?

pat commented 13 years ago

Yeah, if you're using the same TS and Sphinx versions, I'd expect to see it there too.

pat commented 13 years ago

Figured this one out - it worked if you didn't need to set bin_path to locate the Sphinx binaries, but otherwise was making config changes based on the Sphinx version before it was actually determined.

It's now been fixed in both master and rails3 branches.

pabloalr commented 13 years ago

Thanks! I'll try the new version as soon as possible.

I really had no clue on what was going on...

On Thu, Sep 1, 2011 at 9:05 PM, freelancing-god < reply@reply.github.com>wrote:

Figured this one out - it worked if you didn't need to set bin_path to locate the Sphinx binaries, but otherwise was making config changes based on the Sphinx version before it was actually determined.

It's now been fixed in both master and rails3 branches.

Reply to this email directly or view it on GitHub:

https://github.com/freelancing-god/thinking-sphinx/issues/268#issuecomment-1974775

arunn commented 12 years ago

Hi,

I'm facing the issue in Thinking sphinx 1.4.11 gem also when I do ThinkingSphinx.search in my staging environment. But this does not happen in dev mode. Any idea why this might be happening?