Sha256: 67acd59e3b045c7d52caa5774ef89e95f9eb4295246429779e7a445909261772

Contents?: true

Size: 980 Bytes

Versions: 17

Compression:

Stored size: 980 Bytes

Contents

namespace :searchkick do
  desc "reindex a model (specify CLASS)"
  task reindex: :environment do
    class_name = ENV["CLASS"]
    abort "USAGE: rake searchkick:reindex CLASS=Product" unless class_name

    model =
      begin
        Searchkick.load_model(class_name)
      rescue Searchkick::Error => e
        abort e.message
      end

    puts "Reindexing #{model.name}..."
    model.reindex
    puts "Reindex successful"
  end

  namespace :reindex do
    desc "reindex all models"
    task all: :environment do
      # eager load models to populate Searchkick.models
      if Rails.respond_to?(:autoloaders) && Rails.autoloaders.zeitwerk_enabled?
        # fix for https://github.com/rails/rails/issues/37006
        Zeitwerk::Loader.eager_load_all
      else
        Rails.application.eager_load!
      end

      Searchkick.models.each do |model|
        puts "Reindexing #{model.name}..."
        model.reindex
      end
      puts "Reindex complete"
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
searchkick-5.4.0 lib/tasks/searchkick.rake
searchkick-5.3.1 lib/tasks/searchkick.rake
searchkick-5.3.0 lib/tasks/searchkick.rake
searchkick-5.2.4 lib/tasks/searchkick.rake
searchkick-5.2.3 lib/tasks/searchkick.rake
searchkick-5.2.2 lib/tasks/searchkick.rake
searchkick-5.2.1 lib/tasks/searchkick.rake
searchkick-5.2.0 lib/tasks/searchkick.rake
searchkick-5.1.2 lib/tasks/searchkick.rake
searchkick-5.1.1 lib/tasks/searchkick.rake
searchkick-5.1.0 lib/tasks/searchkick.rake
searchkick-5.0.5 lib/tasks/searchkick.rake
searchkick-5.0.4 lib/tasks/searchkick.rake
searchkick-5.0.3 lib/tasks/searchkick.rake
searchkick-5.0.2 lib/tasks/searchkick.rake
searchkick-5.0.1 lib/tasks/searchkick.rake
searchkick-5.0.0 lib/tasks/searchkick.rake