mirror of
https://github.com/apache/lucene.git
synced 2025-02-19 08:27:42 +00:00
git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@495830 13f79535-47bb-0310-9956-ffa450edef68
51 lines
1.4 KiB
Ruby
51 lines
1.4 KiB
Ruby
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
# (the "License"); you may not use this file except in compliance with
|
|
# the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
require 'solr/request/base'
|
|
require 'solr/document'
|
|
require 'solr/request/update'
|
|
require 'rexml/document'
|
|
|
|
module Solr
|
|
module Request
|
|
class AddDocument < Solr::Request::Update
|
|
|
|
# create the request, optionally passing in a Solr::Document
|
|
#
|
|
# request = Solr::Request::AddDocument.new doc
|
|
#
|
|
# as a short cut you can pass in a Hash instead:
|
|
#
|
|
# request = Solr::Request.new :creator => 'Jorge Luis Borges'
|
|
|
|
def initialize(doc={})
|
|
case doc
|
|
when Hash
|
|
@doc = Solr::Document.new(doc)
|
|
when Solr::Document
|
|
@doc = doc
|
|
else
|
|
raise "must pass in Solr::Document or Hash"
|
|
end
|
|
end
|
|
|
|
# returns the request as a string suitable for posting
|
|
|
|
def to_s
|
|
e = REXML::Element.new 'add'
|
|
e.add_element @doc.to_xml
|
|
return e.to_s
|
|
end
|
|
end
|
|
end
|
|
end
|