class RSolr::Message::Adapter::Builder
def add(documents, add_attrs={})
if the doc had a "nickname" field with the value of "Tim".
The "nickname" field would have a boost="20.0"
Each doc element would have a boost="10.0".
and a commitWithin="1.0".
would result in an add element having the attributes boost="10.0"
end
nickname.attrs[:boost] = 20 if nickname.value=='Tim' # boost a field
nickname = doc_msg.field_by_name(:nickname)
doc_msg.attrs[:boost] = 10.00 # boost the document
solr.add({:id=>1, :nickname=>'Tim'}, {:boost=>5.0, :commitWithin=>1.0}) do |doc_msg|
For example:
You can set xml element attributes for each "doc" element or individual "field" elements.
The value yielded to the block is a Message::Document; for each solr doc in "data".
This method can also accept a block.
"add_attrs" can be a hash for setting the add xml element attributes.
If a value is an array, multiple fields will be created.
- each hash should be a simple key=>value pair representing a solr doc.
"data" can be a hash or an array of hashes.
generates "add" xml for updating solr
def add(documents, add_attrs={}) xml.add(add_attrs) do |add_node| documents.each do |doc| # create doc, passing in fields add_node.doc(doc.attrs) do |doc_node| doc.fields.each do |field_obj| doc_node.field(field_obj.value, field_obj.attrs) end end end end end
def commit(opts={})
def commit(opts={}) xml.commit(opts) end
def delete_by_id(ids)
generates a
def delete_by_id(ids) ids = [ids] unless ids.is_a?(Array) xml.delete do |xml| ids.each do |id| xml.id(id) end end end
def delete_by_query(queries)
generates a
def delete_by_query(queries) queries = [queries] unless queries.is_a?(Array) xml.delete do |xml| queries.each do |query| xml.query(query) end end end
def optimize(opts={})
def optimize(opts={}) xml.optimize(opts) end
def rollback
def rollback xml.rollback end
def xml
def xml ::Builder::XmlMarkup.new end