Class: Solr::Request::Delete

Inherits:
Update show all
Defined in:
lib/solr/request/delete.rb

Instance Method Summary collapse

Methods inherited from Update

#handler, #response_format

Methods inherited from Base

#content_type, #handler, #response_format

Constructor Details

#initialize(options) ⇒ Delete

A delete request can be for a specific document id

request = Solr::Request::Delete.new(:id => 1234)

or by query:

request = Solr::Request::Delete.new(:query =>


25
26
27
28
29
30
31
32
33
34
# File 'lib/solr/request/delete.rb', line 25

def initialize(options)
  unless options.kind_of?(Hash) and (options[:id] or options[:query])
    raise Solr::Exception.new("must pass in :id or :query")
  end
  if options[:id] and options[:query]
    raise Solr::Exception.new("can't pass in both :id and :query")
  end
  @document_id = options[:id]
  @query = options[:query]
end

Instance Method Details

#to_sObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/solr/request/delete.rb', line 36

def to_s
  delete_element = Solr::XML::Element.new('delete')
  if @document_id
    id_element = Solr::XML::Element.new('id')
    id_element.text = @document_id
    delete_element.add_element(id_element)
  elsif @query
    query = Solr::XML::Element.new('query')
    query.text = @query 
    delete_element.add_element(query)
  end
  delete_element.to_s
end