Stable version from CRAN
Or the development version from GitHub
Load
Initialize connection. By default, you connect to http://localhost:8983
#> <Solr Client>
#> host: 127.0.0.1
#> path:
#> port: 8983
#> scheme: http
#> errors: simple
#> proxy:
For now, only lists and data.frame’s supported.
#> $responseHeader
#> $responseHeader$status
#> [1] 0
#>
#> $responseHeader$QTime
#> [1] 6513
#>
#>
#> $success
#> $success$`172.20.0.5:8983_solr`
#> $success$`172.20.0.5:8983_solr`$responseHeader
#> $success$`172.20.0.5:8983_solr`$responseHeader$status
#> [1] 0
#>
#> $success$`172.20.0.5:8983_solr`$responseHeader$QTime
#> [1] 5024
#>
#>
#> $success$`172.20.0.5:8983_solr`$core
#> [1] "books_shard1_replica_n1"
#>
#>
#>
#> $warning
#> [1] "Using _default configset. Data driven schema functionality is enabled by default, which is NOT RECOMMENDED for production use. To turn it off: curl http://{host:port}/solr/books/config -d '{\"set-user-property\": {\"update.autoCreateFields\":\"false\"}}'"
#> $responseHeader
#> $responseHeader$rf
#> [1] 1
#>
#> $responseHeader$status
#> [1] 0
#>
#> $responseHeader$QTime
#> [1] 987
Create collection if it doesn’t exist yet
if (!collection_exists(conn, "gettingstarted")) {
collection_create(conn, name = "gettingstarted", numShards = 1)
}
#> $responseHeader
#> $responseHeader$status
#> [1] 0
#>
#> $responseHeader$QTime
#> [1] 6446
#>
#>
#> $success
#> $success$`172.20.0.7:8983_solr`
#> $success$`172.20.0.7:8983_solr`$responseHeader
#> $success$`172.20.0.7:8983_solr`$responseHeader$status
#> [1] 0
#>
#> $success$`172.20.0.7:8983_solr`$responseHeader$QTime
#> [1] 5112
#>
#>
#> $success$`172.20.0.7:8983_solr`$core
#> [1] "gettingstarted_shard1_replica_n1"
#>
#>
#>
#> $warning
#> [1] "Using _default configset. Data driven schema functionality is enabled by default, which is NOT RECOMMENDED for production use. To turn it off: curl http://{host:port}/solr/gettingstarted/config -d '{\"set-user-property\": {\"update.autoCreateFields\":\"false\"}}'"
Add some documents first
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")
#> $responseHeader
#> $responseHeader$rf
#> [1] 1
#>
#> $responseHeader$status
#> [1] 0
#>
#> $responseHeader$QTime
#> [1] 1108
And the documents are now in your Solr database
#> # A tibble: 3 x 4
#> id price name `_version_`
#> <chr> <int> <chr> <dbl>
#> 1 1 100 brown 1.66e18
#> 2 2 500 blue 1.66e18
#> 3 3 2000 pink 1.66e18
Now delete those documents just added
#> $responseHeader
#> $responseHeader$rf
#> [1] 1
#>
#> $responseHeader$status
#> [1] 0
#>
#> $responseHeader$QTime
#> [1] 48
And now they are gone
#> # A tibble: 0 x 0
Add some documents first
#> $responseHeader
#> $responseHeader$rf
#> [1] 1
#>
#> $responseHeader$status
#> [1] 0
#>
#> $responseHeader$QTime
#> [1] 72
And the documents are now in your Solr database
#> # A tibble: 3 x 4
#> id price name `_version_`
#> <chr> <int> <chr> <dbl>
#> 1 1 100 brown 1.66e18
#> 2 2 500 blue 1.66e18
#> 3 3 2000 pink 1.66e18
Now delete those documents just added
#> $responseHeader
#> $responseHeader$rf
#> [1] 1
#>
#> $responseHeader$status
#> [1] 0
#>
#> $responseHeader$QTime
#> [1] 122
And now they are gone
#> # A tibble: 1 x 4
#> id price name `_version_`
#> <chr> <int> <chr> <dbl>
#> 1 1 100 brown 1.66e18
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.
#> $responseHeader
#> $responseHeader$rf
#> [1] 1
#>
#> $responseHeader$status
#> [1] 0
#>
#> $responseHeader$QTime
#> [1] 782
Add a document first, that we can later delete
#> $responseHeader
#> $responseHeader$rf
#> [1] 1
#>
#> $responseHeader$status
#> [1] 0
#>
#> $responseHeader$QTime
#> [1] 100
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")
#> <update>
#> <add>
#> <doc>
#> <field name="id">978-0641723445</field>
#> <field name="cat">book,hardcover</field>
#> <field name="name">The Lightning Thief</field>
#> <field name="author">Rick Riordan</field>
#> <field name="series_t">Percy Jackson and the Olympians</field>
#> <field name="sequence_i">1</field>
#> <field name="genre_s">fantasy</field>
#> <field name="inStock">TRUE</field>
#> <field name="pages_i">384</field>
#> </doc>
#> </add>
#> <delete>
#> <id>456</id>
#> </delete>
#> </update>
#> $responseHeader
#> $responseHeader$rf
#> [1] 1
#>
#> $responseHeader$status
#> [1] 0
#>
#> $responseHeader$QTime
#> [1] 279
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.