سؤال

I'm trying to use sunspot with Rails 4 and I'm running into some issue. When I have only gem 'sunspot_rails', '2.0.0' in my gemfile I get this error:

Note: This task has been moved to the sunspot_solr gem. To install, start and
  stop a local Solr instance, please add sunspot_solr to your Gemfile:
  group :development do
    gem 'sunspot_solr'
 end

But when I add that gem(also v 2.0.0) I get this error:

rake aborted!
Don't know how to build task 'sunspot:solr:start'
/home/toasty/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `eval'
/home/toasty/.rvm/gems/ruby-2.0.0-p195/bin/ruby_noexec_wrapper:14:in `<main>'
(See full trace by running task with --trace)

I have seen this question: Sunspot/Solr raketasks not loading in Rails 3 Mountable Engine but it doesn't seem to work in my case. Does anyone have any ideas? Is sunspot_solr just not compatible with rails 4?

هل كانت مفيدة؟

المحلول

I had this same problem. I don't recall but I found this rake task that you need to add

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

EDIT~ Source of Rakefile

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top