lib/solr_api.rb
# Takes an array of hashes. Each hash has only string or array of strings values. Array is converted into an xml ready
# for either create or update methods of Solr API
#
# See the solr_api library spec for some examples.
Takes an array of hashes. Each hash has only string or array of strings values. Array is converted into an xml ready
for either create or update methods of Solr API

See the solr_api library spec for some examples.
Takes an array of hashes . Each hash has only string or array of strings values . Array is converted into an xml ready for either create or update methods of Solr API See the solr_api library spec for some examples .
def build_solr_xml(command, ruby_data)
    builder = Nokogiri::XML::Builder.new do |sxml|
      sxml.send(command) do
        ruby_data = [ruby_data] if ruby_data.class != Array
        ruby_data.each do |data|
          sxml.doc_ do
            data.keys.each do |key|
              data[key] = [data[key]] if data[key].class != Array
              data[key].each do |val|
                sxml.field(val, :name => key.to_s)
              end
            end
          end
        end
      end
    end
    builder.to_xml
  end
def build_solr_xml ( command , ruby_data ) builder = Nokogiri :: XML :: Builder . new do | sxml | sxml . send ( command ) do ruby_data = [ ruby_data ] if ruby_data . class != Array ruby_data . each do | data | sxml . doc_ do data . keys . each do | key | data [ key ] = [ data [ key ] ] if data [ key ] . class != Array data [ key ] . each do | val | sxml . field ( val , :name => key . to_s ) end end end end end end builder . to_xml end
Takes an array of hashes.
Takes an array of hashes .
command
<not_specific>
ruby_data
<not_specific>