Sha256: 57441674ea269d4282b00d744dd3f06c5a7d47122f99a50278923839282151fd

Contents?: true

Size: 1.11 KB

Versions: 2

Compression:

Stored size: 1.11 KB

Contents

namespace :sunspot do
  namespace :solr do
    desc 'Start the Solr instance'
    task :start => :environment do
      if RUBY_PLATFORM =~ /w(in)?32$/
        abort('This command does not work on Windows. Please use rake sunspot:solr:run to run Solr in the foreground.')
      end
      Sunspot::Rails::Server.new.start
    end

    desc 'Run the Solr instance in the foreground'
    task :run => :environment do
      Sunspot::Rails::Server.new.run
    end

    desc 'Stop the Solr instance'
    task :stop => :environment do
      if RUBY_PLATFORM =~ /w(in)?32$/
        abort('This command does not work on Windows.')
      end
      Sunspot::Rails::Server.new.stop
    end

    task :reindex => :"sunspot:reindex"
  end

  desc 'Reindex all solr models'
  task :reindex => :environment do
    all_files = Dir.glob(File.join(RAILS_ROOT, 'app', 'models', '*.rb'))
    all_models = all_files.map { |path| File.basename(path, '.rb').camelize.constantize }
    sunspot_models = all_models.select { |m| m < ActiveRecord::Base and m.searchable? }

    sunspot_models.each do |model|
      model.reindex :batch_commit => false
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sunspot_rails-1.0.1 lib/sunspot/rails/tasks.rb
sunspot_rails-1.0.0 lib/sunspot/rails/tasks.rb