# NOT RUN {
# start Solr in Cloud mode: bin/solr start -e cloud -noprompt
# connect
(conn <- SolrClient$new())
# create a collection
if (!conn$collection_exists("books")) {
conn$collection_delete("books")
conn$collection_create("books")
}
# Add documents
file <- system.file("examples", "books.xml", package = "solrium")
cat(readLines(file), sep = "\n")
conn$update_xml(file, "books")
# get a document
conn$get(ids = '978-0641723445', "books", wt = "xml")
# atomic update
body <- '
<add>
<doc>
<field name="id">978-0641723445</field>
<field name="genre_s" update="set">mystery</field>
<field name="pages_i" update="inc">1</field>
</doc>
</add>'
conn$update_atomic_xml(body, name="books")
# get the document again
conn$get(ids = '978-0641723445', "books", wt = "xml")
# another atomic update
body <- '
<add>
<doc>
<field name="id">978-0641723445</field>
<field name="price" update="remove">12.5</field>
</doc>
</add>'
conn$update_atomic_xml(body, "books")
# get the document again
conn$get(ids = '978-0641723445', "books", wt = "xml")
# }
Run the code above in your browser using DataLab