Skip to content

Commit

Permalink
Delete multiple documents at once
Browse files Browse the repository at this point in the history
  • Loading branch information
syabruk committed Jan 9, 2024
1 parent c105f9c commit 576f47c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/solr/update/commands/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Delete
COMMAND_KEY = 'delete'.freeze

def self.unnest(array)
array.first
array.size > 1 ? array : array.first
end

attr_reader :options
Expand Down
34 changes: 34 additions & 0 deletions spec/update/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,39 @@
resp = req.run
expect(resp.status).to eq 'OK'
end

it 'deletes multiple documents by id' do
delete_commands = [
Solr::Update::Commands::Delete.new(id: '1'),
Solr::Update::Commands::Delete.new(id: '2')
]

expect(Solr::Request::HttpRequest).to receive(:new).
with(hash_including(body: { 'delete' => delete_commands })).
and_call_original

req = Solr::Update::Request.new(delete_commands)
resp = req.run
expect(resp.status).to eq 'OK'
end

it 'deletes multiple documents by id and filters' do
filters = [
Solr::Query::Request::Filter.new(type: :equal, field: :name_txt_en, value: 'Solrb')
]

delete_commands = [
Solr::Update::Commands::Delete.new(id: '1'),
Solr::Update::Commands::Delete.new(filters: filters)
]

expect(Solr::Request::HttpRequest).to receive(:new).
with(hash_including(body: { 'delete' => delete_commands })).
and_call_original

req = Solr::Update::Request.new(delete_commands)
resp = req.run
expect(resp.status).to eq 'OK'
end
end
end

0 comments on commit 576f47c

Please sign in to comment.