Skip to content

Commit

Permalink
Merge pull request #5166 from sul-dlss/enable_solr
Browse files Browse the repository at this point in the history
Adds enabled flag for solr.
  • Loading branch information
jcoyne authored Aug 19, 2024
2 parents c253c7e + 5c1fb4b commit 80d669a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/services/indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
class Indexer
# @param [Cocina::Models::DROWithMetadata|CollectionWithMetadata|AdminPolicyWithMetadata]
def self.reindex(cocina_object:)
return unless Settings.solr.enabled

solr_doc = Indexing::Builders::DocumentBuilder.for(
model: cocina_object
).to_solr
Expand All @@ -12,6 +14,8 @@ def self.reindex(cocina_object:)
end

def self.delete(druid:)
return unless Settings.solr.enabled

solr.delete_by_id(druid)
solr.commit
end
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ version_service:

# URLs
solr:
enabled: true
select_path: 'select'
timeout: 120
url: 'https://solr.example.com/solr/collection'
Expand Down
25 changes: 25 additions & 0 deletions spec/services/indexer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@
expect(solr).to have_received(:add).with(solr_doc)
expect(solr).to have_received(:commit)
end

context 'when solr is not enabled' do
before do
allow(Settings.solr).to receive(:enabled).and_return(false)
end

it 'does not reindex the object' do
described_class.reindex(cocina_object:)
expect(Indexing::Builders::DocumentBuilder).not_to have_received(:for)
expect(solr).not_to have_received(:add)
expect(solr).not_to have_received(:commit)
end
end
end

describe '#delete' do
Expand All @@ -35,6 +48,18 @@
expect(solr).to have_received(:delete_by_id).with(druid)
expect(solr).to have_received(:commit)
end

context 'when solr is not enabled' do
before do
allow(Settings.solr).to receive(:enabled).and_return(false)
end

it 'does not delete the object' do
described_class.delete(druid:)
expect(solr).not_to have_received(:delete_by_id)
expect(solr).not_to have_received(:commit)
end
end
end

describe '#reindex_later' do
Expand Down

0 comments on commit 80d669a

Please sign in to comment.