knitr::opts_chunk$set( comment = "#>", warning = FALSE, message = FALSE )
Stable version from CRAN
install.packages("solrium")
Or the development version from GitHub
install.packages("devtools") devtools::install_github("ropensci/solrium")
Load
library("solrium")
Initialize connection. By default, you connect to http://localhost:8983
(conn <- SolrClient$new())
For now, only lists and data.frame's supported.
df <- data.frame(id = c(67, 68), price = c(1000, 500000000)) conn$add(df, "books")
conn$delete_by_id(1:2, "books")
ss <- list(list(id = 1, price = 100), list(id = 2, price = 500)) conn$add(ss, "books")
Add some documents first
conn$delete_by_id(1:3, "gettingstarted")
docs <- list(list(id = 1, price = 100, name = "brown"), list(id = 2, price = 500, name = "blue"), list(id = 3, price = 2000L, name = "pink")) conn$add(docs, "gettingstarted")
And the documents are now in your Solr database
conn$search(name = "gettingstarted", params = list(q = "*:*", rows = 3))
Now delete those documents just added
conn$delete_by_id(ids = c(1, 2, 3), "gettingstarted")
And now they are gone
conn$search("gettingstarted", params = list(q = "*:*", rows = 4))
Add some documents first
conn$add(docs, "gettingstarted")
And the documents are now in your Solr database
conn$search("gettingstarted", params = list(q = "*:*", rows = 5))
Now delete those documents just added
conn$delete_by_query(query = "(name:blue OR name:pink)", "gettingstarted")
And now they are gone
conn$search("gettingstarted", params = list(q = "*:*", rows = 5))
This approach is best if you have many different things you want to do at once, e.g., delete and add files and set any additional options. The functions are:
update_xml()
update_json()
update_csv()
There are separate functions for each of the data types as they take slightly different parameters - and to make it more clear that those are the three input options for data types.
file <- system.file("examples", "books.json", package = "solrium") conn$update_json(file, "books")
Add a document first, that we can later delete
ss <- list(list(id = 456, name = "cat")) conn$add(ss, "books")
Now add a new document, and delete the one we just made
file <- system.file("examples", "add_delete.xml", package = "solrium") cat(readLines(file), sep = "\n") conn$update_xml(file, "books")
Note that update_xml()
and update_json()
have exactly the same parameters, but simply use different data input formats. update_csv()
is different in that you can't provide document or field level boosts or other modifications. In addition update_csv()
can accept not just csv, but tsv and other types of separators.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.