Module: Solr::Codec
- Included in:
- Client
- Defined in:
- lib/solr-client.rb
Constant Summary collapse
- ALLOWED_ADD_ATTRS =
[:overwrite, :commitWithin]
Instance Method Summary collapse
- #to_delete_by_id(*ids) ⇒ Object
- #to_delete_by_query(*queries) ⇒ Object
- #to_docs(data, add_attrs = {}) ⇒ Object
Instance Method Details
#to_delete_by_id(*ids) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/solr-client.rb', line 41 def to_delete_by_id(*ids) ids.flatten! content = '<?xml version="1.0" encoding="UTF-8"?><delete>' ids.each { |id| content << '<id>' << h(id) << '</id>' } content << '</delete>' end |
#to_delete_by_query(*queries) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/solr-client.rb', line 48 def to_delete_by_query(*queries) queries.flatten! content = '<?xml version="1.0" encoding="UTF-8"?><delete>' queries.each { |query| content << '<query>' << h(query) << '</query>' } content << '</delete>' end |
#to_docs(data, add_attrs = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/solr-client.rb', line 12 def to_docs(data, add_attrs={}) attrs = add_attrs.map do |k, v| "#{k}=\"#{v}\"" if ALLOWED_ADD_ATTRS.include?(k) && !v.nil? end.join(" ") attrs = " " + attrs unless attrs.empty? content = '<?xml version="1.0" encoding="UTF-8"?>'; content += "<add#{attrs}>" data = [data] unless data.is_a?(Array) data.each do |doc| content << '<doc>' doc.each do |field_key, field_values| next if field_values.nil? field_values = [field_values] unless field_values.is_a?(Array) field_values.each do |field_value| content << '<field name="' << h(field_key) << '">' case field_value when Time, DateTime field_value = field_value.strftime("%Y-%m-%dT%H:%M:%SZ") end content << h(field_value) content << '</field>' end end content << '</doc>' end content << '</add>' end |