Search code examples
ruby-on-rails-3.2rvmthinking-sphinx

Thinking Sphinx not generating results


Generating error:

undefined method `inject' for nil:NilClass

Notwithstanding the discussion at: https://github.com/pat/thinking-sphinx/issues/408#issuecomment-12593562 it appears that I do have mySQL and sphinx properly installed for my postgre-based application

MacBook-Pro-di-jerdvo:saim jerdvo$ brew install sphinx --mysql
Error: sphinx-2.0.3 already installed
MacBook-Pro-di-jerdvo:saim jerdvo$ brew install mysql
Error: mysql-5.5.20 already installed

gemfile includes

gem 'rails', '3.2.13'
gem 'pg', '0.14.1'
gem 'mysql2', '0.3.12b5'
gem 'thinking-sphinx', '3.0.3'

search parameters are being captured

{"utf8"=>"✓", "staticpage_search"=>{"terms"=>"Messina"}}

search model is running code

  def search(options = {})
    extra_conditions = options.delete(:conditions) || {}
    order = options.delete(:order) || '@weight DESC'
    extra_with = options.delete(:with) || {}

    with = search_with.merge(extra_with)
    conditions = search_conditions.merge(extra_conditions)

    base_class.search sanitized_terms, :conditions => conditions, :with => with, :page => page, :per_page => per_page, :sort_mode => :extended, :order => order, :retry_stale => true, :match_mode => :extended
  end

  def sanitized_terms
    @terms ||= ""
    sanitize(@terms)
  end

  def sanitize(s)
    if s.respond_to? :gsub
      s.gsub("/", "\\/")
    else
      s
    end
  end

Solution

  • Two things to note:

    • You need Sphinx 2.0.6 or newer for TS v3 on MacOS X (due to bugs in earlier Sphinx versions with threaded daemons on OS X only).
    • You need Sphinx compiled with MySQL support. Just having both MySQL and Sphinx on your system doesn't guarantee this - the best way to check is to use MySQL as your app database (just temporarily - I prefer PostgreSQL too), check that Sphinx indexes fine with that setup, then you can be sure MySQL support was compiled. That said, when you update to 2.0.6 or newer (may need to update your brew recipes), I'll be surprised if that's not the case.