Sphinx not starting up on Heroku

Shawn's Avatar

Shawn

23 Jan, 2013 07:30 PM

I upgraded my Sphinx gems for my RoR project and I'm getting all sorts of errors. First there was a 'mysql2 gem missing' error, and now I'm getting this one:

/app/vendor/bundle/ruby/1.9.1/gems/flying-sphinx-0.8.5/lib/flying_sphinx/heroku_shared_adapter.rb:1:in `': uninitialized constant ThinkingSphinx::PostgreSQLAdapter (NameError)

Any ideas?

  1. 1 Posted by Shawn on 23 Jan, 2013 07:35 PM

    Shawn's Avatar

    Here are my gems:

    gem 'thinking-sphinx', '3.0.0'
    gem 'flying-sphinx', '0.8.5'

  2. 2 Posted by Shawn on 23 Jan, 2013 08:00 PM

    Shawn's Avatar

    When I try to run configure, I get this error:

    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/dynamic_matchers.rb:50:in method_missing': undefined methoddefine_index' for #<Class:0x00000006b8e358> (NoMethodError)

    from /app/app/models/user.rb:69:in `<class:User>'
    from /app/app/models/user.rb:3:in `<top (required)>'
    

    But my User model DOES have a define_index defined.

  3. Support Staff 3 Posted by Pat Allan on 23 Jan, 2013 08:22 PM

    Pat Allan's Avatar

    Hi Shawn

    Upgrading to Thinking Sphinx 3.0 is not a simple matter of just changing gems:
    https://groups.google.com/d/msg/thinking-sphinx/QM0BlS3gg3k/s61pfCBBTUoJ
    https://github.com/pat/thinking-sphinx/blob/master/README.textile

    Index definitions are now in their own files, so that's why you're getting the define_index errors. Also, you'll need to use the latest from the ts3 branch of flying-sphinx:

        gem 'flying-sphinx',
          :git => 'git://github.com/flying-sphinx/flying-sphinx.git',
          :ref => 'f87bbbd519'

    Kind regards,

    Pat Allan

  4. 4 Posted by Shawn on 23 Jan, 2013 09:15 PM

    Shawn's Avatar

    Thanks. I started migrating over to the new index files, but now I'm getting this error after switching to your recommended flying sphinx version:

    /app/vendor/bundle/ruby/1.9.1/gems/bundler-1.3.0.pre.5/lib/bundler/runtime.rb:31:in `block in setup': You have already activated flying-sphinx 0.8.5, but your Gemfile requires flying-sphinx 0.8.4. Using bundle exec may solve this. (Gem::LoadError)

  5. Support Staff 5 Posted by Pat Allan on 23 Jan, 2013 09:19 PM

    Pat Allan's Avatar

    Try adding bundle exec to the `heroku run` commands - e.g.: heroku run bundle exec flying-sphinx configure

  6. 6 Posted by Shawn on 23 Jan, 2013 09:29 PM

    Shawn's Avatar

    I added bundle exec and now I have this error:

    /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:494:in load_missing_constant': Object is not missing constant Rails! (NameError) from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:192:inblock in const_missing' from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:in each' from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:190:inconst_missing' from /app/app/indices/project_index.rb:11:in `block in '

    My project_index.rb looks like this:

    ThinkingSphinx::Index.define :user, :with => :active_record, :delta => true do

    # fields indexes title, :sortable => true indexes description indexes taggings.tag.name, :as => :tags

    # attributes has created_at, updated_at

    if Rails.env.production? || Rails.env.staging? set_property :delta => FlyingSphinx::DelayedDelta end end

    What about the Rails constant is wrong?

  7. Support Staff 7 Posted by Pat Allan on 23 Jan, 2013 09:49 PM

    Pat Allan's Avatar

    Try changing the Rails references in your index definition to ::Rails instead.

  8. 8 Posted by Shawn on 23 Jan, 2013 09:53 PM

    Shawn's Avatar

    I went and just removed those lines from the index definitions, but now I'm getting this error:

    /app/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.3/lib/active_record/associations/join_dependency/join_association.rb:34:in initialize': undefined methodcheck_validity!' for nil:NilClass (NoMethodError) from /app/vendor/bundle/ruby/1.9.1/gems/polyamorous-0.5.0/lib/polyamorous/join_association.rb:24:in initialize_with_polymorphism' from /app/vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/active_record/associations.rb:43:innew'

  9. Support Staff 9 Posted by Pat Allan on 23 Jan, 2013 11:21 PM

    Pat Allan's Avatar

    Is either the taggings or tag association polymorphic? I'm not familiar with the polyamorous gem, so I don't know how it could impact this setup.

  10. 10 Posted by Shawn Bernard on 23 Jan, 2013 11:46 PM

    Shawn Bernard's Avatar

    It was definitely working before the upgrade.

  11. Support Staff 11 Posted by Pat Allan on 23 Jan, 2013 11:55 PM

    Pat Allan's Avatar

    Yup, but polymorphic support has changed a bit with TS v3. It now doesn't make potentially slow queries on your database to determine which models are available through a polymorphic association, but because of that, you need to specify which models should be considered with a polymorphic association:

        indexes posts.source.name, :as => :source_name

        polymorphs posts.source, :to => %w( User Project )

    Also, you'll need to be running the latest from GitHub - the required commits weren't part of 3.0.0:

        gem 'thinking-sphinx',
          :git => 'git://github.com/pat/thinking-sphinx.git',
          :ref => '85336fc822'

    Cheers

    Pat

  12. 12 Posted by Shawn on 24 Jan, 2013 03:02 AM

    Shawn's Avatar

    I think I got over the hump, but now I'm getting an error when I perform the search:

    2013-01-24T02:22:19+00:00 app[web.3]: NoMethodError (undefined method 'stringify_keys!' for test 2013-01-24T02:22:19+00:00 app[web.3]: app/controllers/search_controller.rb:5:in `search'

    The line of code that the error is referring to is this:

     project_results = Project.search params[:query], :include => :user, :star => true, :sort_mode => :extended, :order => "@relevance DESC, title DESC"
    
  13. Support Staff 13 Posted by Pat Allan on 24 Jan, 2013 03:12 AM

    Pat Allan's Avatar

    Hi Shawn

    Good to hear progress is being made. What's the full stack of this new error?

  14. 14 Posted by Shawn Bernard on 24 Jan, 2013 03:19 AM

    Shawn Bernard's Avatar

    That's it. Just those two lines.

  15. Support Staff 15 Posted by Pat Allan on 24 Jan, 2013 03:25 AM

    Pat Allan's Avatar

    Hmm. What's the full contents of that method in your controller?

  16. 16 Posted by Shawn Bernard on 24 Jan, 2013 03:34 AM

    Shawn Bernard's Avatar

    That's the first line of the method:

      def search
        project_results = Project.search params[:query], :include => :user, :star => true, :sort_mode => :extended, :order => "@relevance DESC, title DESC"
        user_results = User.search params[:query], :star => true, :sort_mode => :extended, :order => "@relevance DESC, username DESC"
        ...

  17. 17 Posted by Shawn on 24 Jan, 2013 03:37 AM

    Shawn's Avatar

    And the call to the method looks like this:

    2013-01-24T03:33:27+00:00 app[web.1]: Started GET "/search/search.json?query=josh" for 166.147.83.163 at 2013-01-24 03:33:27 +0000
    2013-01-24T03:33:27+00:00 app[web.1]: Processing by SearchController#search as JSON
    2013-01-24T03:33:27+00:00 app[web.1]: Parameters: {"query"=>"josh"}

  18. Support Staff 18 Posted by Pat Allan on 24 Jan, 2013 04:16 AM

    Pat Allan's Avatar

    I'm at a loss to where this error's coming from - there's no calls to stringify_keys! in the Thinking Sphinx source. Does it work locally? I'm hoping there's a deeper stack trace available somewhere.

  19. 19 Posted by shawn on 31 Jan, 2013 08:52 PM

    shawn's Avatar

    I still don't know what's going on. Now I'm getting this:

    undefined method `search=' for #MetaSearch::Searches::Project:0x007fa5ac702ea8

    My indices/project_index.rb looks like:

    ThinkingSphinx::Index.define :project, :with => :active_record, :delta => true do

    # fields indexes title, :sortable => true indexes description indexes taggings.tag.name, :as => :tags

    # attributes has created_at, updated_at end

  20. 20 Posted by shawn on 31 Jan, 2013 08:53 PM

    shawn's Avatar

    Do you guys have a full working example you can post for the v3.0.0 release? There is nothing anywhere as far as I can see.

  21. Support Staff 21 Posted by Pat Allan on 31 Jan, 2013 09:47 PM

    Pat Allan's Avatar

    I'm not sure if MetaSearch is getting in the way... do you have a full stack trace of that error?

    At this point, there's no sample apps with TS v3 that I can point to - though to be honest, if you've got MetaSearch and Thinking Sphinx in the same app, you're not dealing with a standard setup.

  22. 22 Posted by shawn on 31 Jan, 2013 10:35 PM

    shawn's Avatar

    The method to call search is different in 3.0.0. It used to be Project.search, but now it's ThinkingSphinx.search. That solved one issue, but now I'm getting a MySQL error on Heroku:

    2013-01-31T22:33:14+00:00 app[web.4]: Sphinx Query (23.7ms) SELECT * FROM project_core, project_delta, user_core, user_delta WHERE sphinx_deleted = 0 LIMIT 0, 20
    2013-01-31T22:33:14+00:00 app[web.4]: Completed 500 Internal Server Error in 260ms
    2013-01-31T22:33:14+00:00 app[web.4]:
    2013-01-31T22:33:14+00:00 app[web.4]: Mysql2::Error (Lost connection to MySQL server at 'reading authorization packet', system error: 0):
    2013-01-31T22:33:14+00:00 app[web.4]: app/controllers/search_controller.rb:13:in `search'

  23. Support Staff 23 Posted by Pat Allan on 31 Jan, 2013 10:55 PM

    Pat Allan's Avatar

    Well, that's progress. Is this error still persisting? And what's your app's name? I'll have a look at the appropriate Sphinx server...

  24. 24 Posted by Shawn Bernard on 31 Jan, 2013 11:08 PM

    Shawn Bernard's Avatar

    My app on heroku is at young-galaxy-1140, and it looks like my Sphinx server is rotterdam.

    -S

  25. Support Staff 25 Posted by Pat Allan on 31 Jan, 2013 11:14 PM

    Pat Allan's Avatar

    Have you run either `heroku run bundle exec flying-sphinx rebuild` or `heroku run rake fs:rebuild` since switching gem versions? The sphinx configuration file on the server looks like it was generated with an older version of Thinking Sphinx.

  26. 26 Posted by Shawn Bernard on 31 Jan, 2013 11:33 PM

    Shawn Bernard's Avatar

    OK, I ran it and now I'm getting this error:

    2013-01-31T23:32:34+00:00 app[web.3]: Sphinx Query (25.1ms) SELECT * FROM `project_core`, `project_delta` WHERE MATCH('test @sphinx_internal_class_name (Project)') AND sphinx_deleted = 0 ORDER BY @relevance DESC, title DESC LIMIT 0, 20
    2013-01-31T23:32:34+00:00 app[web.3]: Completed 500 Internal Server Error in 199ms
    2013-01-31T23:32:34+00:00 app[web.3]:
    2013-01-31T23:32:34+00:00 app[web.3]: Mysql2::Error (sphinxql: syntax error, unexpected USERVAR, expecting IDENT (or 5 other tokens) near '@relevance DESC, title DESC LIMIT 0, 20; SHOW META'):
    2013-01-31T23:32:34+00:00 app[web.3]: app/controllers/search_controller.rb:11:in `search'

  27. Support Staff 27 Posted by Pat Allan on 01 Feb, 2013 12:31 AM

    Pat Allan's Avatar

    Right, so for some reason Sphinx decided to no longer support @relevance in SphinxQL queries - but @weight is fine and means the same thing, so just use that instead.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac