Search code examples
ruby-on-railsconfigsunspot

Rails sunspot error on sunspot:solr:start


I'm actually trying to install and use the Sunspot gem for Rails (https://github.com/sunspot/sunspot). So far here is what I did. I added the dependencies in my Gemfile :

gem 'sunspot_rails'
gem 'sunspot_solr'

Then I did run bundle and create the configuration file using rails generate sunspot_rails:install. So far so good.

But then, when I tried to run bundle exec rake sunspot:solr:start, I'm facing the following error :

rake aborted!
Don't know how to build task 'sunspot:solr:start'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/task_manager.rb:49:in `[]'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:148:in `invoke_task'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `each'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:106:in `block in top_level'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:100:in `top_level'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:78:in `block in run'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
/Users/project/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/rake-10.1.0/bin/rake:33:in `<top (required)>'
/Users/project/.rbenv/versions/2.0.0-p247/bin/rake:23:in `load'
/Users/project/.rbenv/versions/2.0.0-p247/bin/rake:23:in `<main>'

I'm actually using Rails 4 and Ruby 2.0.0. Did anyone already face the same issue or know a way to fix that?

Thanks a lot for the help


Solution

  • I had the same error that I was able to solve by adding the following file.

    Source of Rakefile Duplicate Question

    lib/tasks/solr.rake
    
    namespace :sunspot do
      namespace :solr do
      desc 'Start the Solr instance'
        task :start => :environment do
          case RUBY_PLATFORM
            when /w(in)?32$/, /java$/
              abort("This command is not supported on #{RUBY_PLATFORM}. " +
              "Use rake sunspot:solr:run to run Solr in the foreground.")
         end
    
      if defined?(Sunspot::Rails::Server)
        Sunspot::Rails::Server.new.start
      else
        Sunspot::Solr::Server.new.start
      end
      puts "Successfully started Solr ..."
    end
    
    desc 'Run the Solr instance in the foreground'
    task :run => :environment do
      if defined?(Sunspot::Rails::Server)
        Sunspot::Rails::Server.new.run
      else
        Sunspot::Solr::Server.new.run
      end
    end
    
    desc 'Stop the Solr instance'
    task :stop => :environment do
      case RUBY_PLATFORM
      when /w(in)?32$/, /java$/
        abort("This command is not supported on #{RUBY_PLATFORM}. " +
              "Use rake sunspot:solr:run to run Solr in the foreground.")
      end
    
      if defined?(Sunspot::Rails::Server)
        Sunspot::Rails::Server.new.stop
      else
        Sunspot::Solr::Server.new.stop
      end
      puts "Successfully stopped Solr ..."
    end
    
    # for backwards compatibility
    task :reindex => :"sunspot:reindex"
    end
    end