diff --git a/app/services/hyrax/solr_service.rb b/app/services/hyrax/solr_service.rb index 7e429b33ac..74a1bc3ac9 100644 --- a/app/services/hyrax/solr_service.rb +++ b/app/services/hyrax/solr_service.rb @@ -37,7 +37,8 @@ def select_path 'Use `Hyrax.config.solr_select_path` instead' end - delegate :add, :commit, :count, :delete, :get, :instance, :ping, :post, :query, :delete_by_query, :search_by_id, to: :new + delegate :add, :commit, :count, :delete, :get, :instance, :ping, :post, + :query, :delete_by_query, :search_by_id, :wipe!, to: :new end # Wraps rsolr get @@ -100,6 +101,12 @@ def delete(id) connection.delete_by_id(id, params: COMMIT_PARAMS) end + # Deletes all solr documents + def wipe! + delete_by_query("*:*") + commit + end + # Wraps rsolr add # @return [Hash] the hash straight form rsolr def add(solr_doc, commit: true) diff --git a/spec/services/hyrax/solr_service_spec.rb b/spec/services/hyrax/solr_service_spec.rb index 76a03c92a5..0210188dbd 100644 --- a/spec/services/hyrax/solr_service_spec.rb +++ b/spec/services/hyrax/solr_service_spec.rb @@ -197,6 +197,25 @@ end end + describe ".wipe!" do + it "calls solr" do + expect(mock_conn).to receive(:delete_by_query).with("*:*", params: {}) + allow(described_class).to receive(:instance).and_return(double("instance", conn: mock_conn)) + expect(mock_conn).to receive(:commit) + described_class.wipe! + end + + context "when use_valkyrie: true" do + let(:service) { described_class.new(use_valkyrie: true) } + + it "uses valkyrie solr based on config query_index_from_valkyrie" do + expect(mock_conn).to receive(:delete_by_query).with("*:*", params: {}) + expect(mock_conn).to receive(:commit) + service.wipe! + end + end + end + describe '.instance' do let(:mock_instance) { double("instance", conn: mock_conn) } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index bd213e1e6e..8d4ff388ca 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -108,7 +108,6 @@ def clean_active_fedora_repository # The JS is executed in a different thread, so that other thread # may think the root path has already been created: ActiveFedora.fedora.connection.send(:init_base_path) - Hyrax.persister.wipe! if Hyrax.config.query_index_from_valkyrie end RSpec.configure do |config| @@ -236,6 +235,10 @@ def clean_active_fedora_repository config.before(:example, :clean_repo) do clean_active_fedora_repository Hyrax::RedisEventStore.instance.redis.flushdb + + # Not needed to clean the Solr core used by ActiveFedora since + # clean_active_fedora_repository will wipe that core + Hyrax::SolrService.wipe! if Hyrax.config.query_index_from_valkyrie end # Use this example metadata when you want to perform jobs inline during testing.