Module: Solrizer::XML::Extractor
- Defined in:
- lib/solrizer/xml/extractor.rb
Instance Method Summary collapse
-
#xml_to_solr(text, solr_doc = Hash.new, mapper = Solrizer.default_field_mapper) ⇒ Object
This method extracts solr fields from simple xml If you want to do anything more nuanced with the xml, use OM instead.
Instance Method Details
#xml_to_solr(text, solr_doc = Hash.new, mapper = Solrizer.default_field_mapper) ⇒ Object
This method extracts solr fields from simple xml If you want to do anything more nuanced with the xml, use OM instead.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/solrizer/xml/extractor.rb', line 11 def xml_to_solr( text, solr_doc=Hash.new, mapper = Solrizer.default_field_mapper ) doc = XmlSimple.xml_in( text ) doc.each_pair do |name, value| if value.kind_of?(Array) if value.first.kind_of?(Hash) # This deals with the way xml-simple handles nodes with attributes solr_doc.merge!({mapper.solr_name(name, :stored_searchable, :type=>:text).to_sym => "#{value.first["content"]}"}) elsif value.length > 1 solr_doc.merge!({mapper.solr_name(name, :stored_searchable, :type=>:text).to_sym => value}) else solr_doc.merge!({mapper.solr_name(name, :stored_searchable, :type=>:text).to_sym => "#{value.first}"}) end else solr_doc.merge!({mapper.solr_name(name, :stored_searchable, :type=>:text).to_sym => "#{value}"}) end end return solr_doc end |