Skip to content

Commit

Permalink
Merge pull request #2339 from projectblacklight/index-seed-task
Browse files Browse the repository at this point in the history
Allow blacklight:index:seed to pull the fixture file from an env vari…
  • Loading branch information
jcoyne authored Sep 29, 2020
2 parents 3180f9c + f2e954a commit 8a65b7e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/railties/blacklight.rake
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ namespace :blacklight do
end

namespace :index do
desc "Put sample data into solr"
task seed: [:environment] do
desc <<-EODESC.gsub(/\n\s*/, ' ')
Index sample data (from FILE, ./spec/fixtures/sample_solr_documents.yml in this application,
or the test fixtures from blacklight) into solr.
EODESC
task seed: [:environment] do
require 'yaml'

docs = YAML.safe_load(File.open(File.join(Blacklight.root, 'spec', 'fixtures', 'sample_solr_documents.yml')))
app_file = Rails.root && Rails.root + 'spec/fixtures/sample_solr_documents.yml'
file = ENV['FILE'] ||
(app_file && File.exist?(app_file) && app_file) ||
File.join(Blacklight.root, 'spec', 'fixtures', 'sample_solr_documents.yml')
docs = YAML.safe_load(File.open(file))
conn = Blacklight.default_index.connection
conn.add docs
conn.commit
Expand Down

0 comments on commit 8a65b7e

Please sign in to comment.