1

A have project on rails 3.2.17 with db MySQL. Use Thinking Sphinx 3.1. And I have only two models in index: Group and Product.

In development mode everything works perfectly, even on production server. I created development db on production server for testing.

But when I try run : export RAILS_ENV=production rake ts:rebuild or rake ts:configure

I get error:

Generating configuration to /var/www/site/shared/config/sphinx.production.conf
rake aborted!
NameError: uninitialized constant Group
/var/www/site/shared/bundle/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/inflector/methods.rb:230:in `block in constantize'
/var/www/site/shared/bundle/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/inflector/methods.rb:229:in `each'
/var/www/site/shared/bundle/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/inflector/methods.rb:229:in `constantize'
/var/www/site/shared/bundle/ruby/2.1.0/gems/activesupport-3.2.17/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/core/index.rb:43:in `model'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/index.rb:9:in `append_source'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/interpreter.rb:63:in `__source'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/interpreter.rb:20:in `indexes'
/var/www/site/releases/20140927155218/app/indices/group_index.rb:10:in `block in <top (required)>'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/core/interpreter.rb:3:in `translate!'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/core/index.rb:39:in `interpret_definition!'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/active_record/index.rb:32:in `sources'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:31:in `collect'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:31:in `sources'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:19:in `attributes'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:23:in `sphinx_internal_ids'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration/consistent_ids.rb:7:in `reconcile'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:87:in `render'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `block in render_to_file'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/configuration.rb:96:in `render_to_file'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/rake_interface.rb:13:in `configure'
/var/www/site/shared/bundle/ruby/2.1.0/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/tasks.rb:4:in `block (2 levels) in <top (required)>'
Tasks: TOP => ts:configure
(See full trace by running task with --trace)

I couldn't understand why.

Help me please!

My index definitions

app/indices/group_index.rb

ThinkingSphinx::Index.define :group, :with => :active_record do
  # fields
#  indexes subject, :sortable => true
#  indexes content
#  indexes author.name, :as => :author, :sortable => true

  # attributes
#  has author_id, created_at, updated_at

    indexes :title_ua
    indexes :title_ru
    indexes :description_ua
    indexes :description_ru
    indexes :content_ua
    indexes :content_ru


end

app/indices/product_index.rb

ThinkingSphinx::Index.define :product, :with => :active_record do
  # fields
#  indexes subject, :sortable => true
#  indexes content
#  indexes author.name, :as => :author, :sortable => true

  # attributes
#  has author_id, created_at, updated_at

    indexes :title_ua
    indexes :title_ru
    indexes :description_ua
    indexes :description_ru
    indexes :brief_ua
    indexes :brief_ru
    indexes :permalink
    indexes :asin
    indexes :article
    indexes :mpn
    indexes :model


end

Group model migration file:

class CreateGroups < ActiveRecord::Migration
  def change
    create_table :groups do |t|
      t.string     :permalink
      t.integer    :position
      t.string     :title_ua
      t.string     :title_ru
      t.text       :description_ua, default: ''
      t.text       :description_ru, default: ''
      t.text       :content_ua,     default: ''
      t.text       :content_ru,     default: ''
      t.integer    :code_1c
      t.integer    :main_page_position
      t.string     :ancestry
      t.string     :category
      t.references :author
      t.references :update_by_user

      t.timestamps
    end
    add_index :groups, :permalink
    add_index :groups, :ancestry
  end
end
greenif
  • 1,055
  • 1
  • 12
  • 25
  • Can you share your index definitions? – pat Sep 27 '14 at 23:05
  • The error is pointing to line 10 of your group_index.rb file - yet, there's not 10 lines there. Is anything different in the actual file? – pat Sep 28 '14 at 03:01
  • I post my Group model migration file. But I do not think that it is a problem in index file, first - it very simple, second - it works in development mode. – greenif Sep 28 '14 at 06:28
  • Do you have threadsafe enabled for your production environment? – pat Sep 28 '14 at 14:56
  • Yes, this was the problem! Thanks you!!! – greenif Sep 30 '14 at 23:51

1 Answers1

1

As noted in the comments, using threadsafe was causing issues. I've come across this before (I don't think it's related to Thinking Sphinx, just to do with how Rails' autoloading and Rake work together when threadsafe is enabled in 3.2.x.

I've used the following approach - which I'm quite sure should be fine provided no rake tasks are doing anything that's multi-threaded:

config.threadsafe! unless defined?($rails_rake_task) && $rails_rake_task

Discussed in more detail here.

pat
  • 16,116
  • 5
  • 40
  • 46