# NOT RUN {
(conn <- SolrClient$new())
# create the boooks collection
if (!collection_exists(conn, "books")) {
collection_create(conn, name = "books", numShards = 1)
}
# Documents in a list
ss <- list(list(id = 1, price = 100), list(id = 2, price = 500))
add(ss, conn, name = "books")
conn$get(c(1, 2), "books")
# Documents in a data.frame
## Simple example
df <- data.frame(id = c(67, 68), price = c(1000, 500000000))
add(df, conn, "books")
df <- data.frame(id = c(77, 78), price = c(1, 2.40))
add(df, conn, "books")
## More complex example, get file from package examples
# start Solr in Schemaless mode first: bin/solr start -e schemaless
file <- system.file("examples", "books.csv", package = "solrium")
x <- read.csv(file, stringsAsFactors = FALSE)
class(x)
head(x)
if (!collection_exists(conn, "mybooks")) {
collection_create(conn, name = "mybooks", numShards = 2)
}
add(x, conn, "mybooks")
# Use modifiers
add(x, conn, "mybooks", commit_within = 5000)
# Get back XML instead of a list
ss <- list(list(id = 1, price = 100), list(id = 2, price = 500))
# parsed XML
add(ss, conn, name = "books", wt = "xml")
# raw XML
add(ss, conn, name = "books", wt = "xml", raw = TRUE)
# }
Run the code above in your browser using DataLab