【问题标题】:rake sunspot:solr:start throwing an errorrake sunspot:solr:start 抛出错误
【发布时间】:2013-07-12 22:43:39
【问题描述】:

我正在尝试在 Rails 4 中使用 sunspot,但遇到了一些问题。当我的 gemfile 中只有 gem 'sunspot_rails', '2.0.0' 时,我收到此错误:

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

但是当我添加那个 gem(也是 v 2.0.0)时,我得到了这个错误:

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)

我看过这个问题: Sunspot/Solr raketasks not loading in Rails 3 Mountable Engine 但在我的情况下似乎不起作用。有没有人有任何想法? sunspot_solr 是否与 rails 4 不兼容?

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-4 sunspot sunspot-rails sunspot-solr


【解决方案1】:

我遇到了同样的问题。我不记得了,但我发现了你需要添加的这个 rake 任务

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

编辑~Source of Rakefile

【讨论】:

    猜你喜欢
    • 2015-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-25
    • 2018-02-05
    • 2012-10-13
    相关资源
    最近更新 更多