Skip to content

Commit

Permalink
Allow blacklight:index:seed to pull the fixture file from an env vari…
Browse files Browse the repository at this point in the history
…able or a well-known location in the app
  • Loading branch information
cbeer committed Sep 29, 2020
1 parent 3180f9c commit f2e954a
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 f2e954a

Please sign in to comment.