add: Add documents from R objects

Description Usage Arguments Details See Also Examples

View source: R/add.R

Description

Add documents from R objects

Usage

1
2
add(x, name, commit = TRUE, commit_within = NULL, overwrite = TRUE,
  boost = NULL, wt = "json", raw = FALSE, ...)

Arguments

x

Documents, either as rows in a data.frame, or a list.

name

(character) A collection or core name. Required.

commit

(logical) If TRUE, documents immediately searchable. Default: TRUE

commit_within

(numeric) Milliseconds to commit the change, the document will be added within that time. Default: NULL

overwrite

(logical) Overwrite documents with matching keys. Default: TRUE

boost

(numeric) Boost factor. Default: NULL

wt

(character) One of json (default) or xml. If json, uses fromJSON to parse. If xml, uses read_xml to parse

raw

(logical) If TRUE, returns raw data in format specified by wt param

...

curl options passed on to GET

Details

Works for Collections as well as Cores (in SolrCloud and Standalone modes, respectively)

See Also

update_json, update_xml, update_csv for adding documents from files

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
## Not run: 
solr_connect()

# create the boooks collection
if (!collection_exists("books")) {
  collection_create(name = "books", numShards = 2)
}

# Documents in a list
ss <- list(list(id = 1, price = 100), list(id = 2, price = 500))
add(ss, name = "books")

# Documents in a data.frame
## Simple example
df <- data.frame(id = c(67, 68), price = c(1000, 500000000))
add(x = df, "books")
df <- data.frame(id = c(77, 78), price = c(1, 2.40))
add(x = df, "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("mybooks")) {
  collection_create(name = "mybooks", numShards = 2)
}
add(x, "mybooks")

# Use modifiers
add(x, "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, name = "books", wt = "xml")
# raw XML
add(ss, name = "books", wt = "xml", raw = TRUE)

## End(Not run)


solrium documentation built on May 19, 2017, 4:38 p.m.
Search within the solrium package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs in the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.