design_search: Search design documents

Description Usage Arguments Value Options to pass to params, body, or queries params References Examples

View source: R/design_search.R

Description

Search design documents

Usage

1
2
3
4
design_search(cushion, dbname, design, view, params = list(), body = list(),
  as = "list", ...)

design_search_many(cushion, dbname, design, view, queries, as = "list", ...)

Arguments

cushion

A Cushion object. Required.

dbname

(character) Database name. required.

design

(character) Design document name. this is the design name without _design/, which is prepended internally. required.

view

(character) a view, same as fxn param in design_create_(). required.

params

query parameters. a named list

body

same as params, but if any given, a POST request is sent (if body non-NULL, params also sent). a named list

as

(character) One of list (default) or json

...

Curl args passed on to HttpClient

queries

a list of named lists of queries

Value

JSON as a character string or a list (determined by the as parameter)

Options to pass to params, body, or queries params

References

http://docs.couchdb.org/en/latest/api/ddoc/views.html

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
## Not run: 
(x <- Cushion$new())

file <- system.file("examples/omdb.json", package = "sofa")
strs <- readLines(file)

## create a database
if ("omdb" %in% db_list(x)) {
  invisible(db_delete(x, dbname="omdb"))
}
db_create(x, dbname='omdb')

## add the documents
invisible(db_bulk_create(x, "omdb", strs))

# Create a view, the easy way, but less flexible
design_create(x, dbname='omdb', design='view1', fxnname="foobar1")
design_create(x, dbname='omdb', design='view2', fxnname="foobar2",
  value="doc.Country")
design_create(x, dbname='omdb', design='view5', fxnname="foobar3",
  value="[doc.Country,doc.imdbRating]")
design_create_(x, dbname='omdb', design='view6', fxnname="foobar4",
  fxn = "function(doc){emit(doc._id,doc.Country)}")

# Search using a view
compact <- function(l) Filter(Negate(is.null), l)
res <- design_search(x, dbname='omdb', design='view2', view ='foobar2')
head(
  do.call(
    "rbind.data.frame",
    Filter(
      function(z) length(z) == 2,
      lapply(res$rows, function(x) compact(x[names(x) %in% c('id', 'value')]))
    )
  )
)

res <- design_search(x, dbname='omdb', design='view5', view = 'foobar3')
head(
  structure(do.call(
    "rbind.data.frame",
    lapply(res$rows, function(x) x$value)
  ), .Names = c('Country', 'imdbRating'))
)

# query parameters
## limit
design_search(x, dbname='omdb', design='view5', view = 'foobar3',
  params = list(limit = 5))
## limit and skip
design_search(x, dbname='omdb', design='view5', view = 'foobar3',
  params = list(limit = 5, skip = 3))

# POST request
ids <- vapply(db_alldocs(x, dbname='omdb')$rows[1:3], "[[", "", "id")
res <- design_search(x, dbname='omdb', design='view6', view = 'foobar4',
  body = list(keys = ids), verbose = TRUE)
res

# Many queries at once in a POST request
queries <- list(
  list(keys = ids),
  list(limit = 3, skip = 2)
)
design_search_many(x, 'omdb', 'view6', 'foobar4', queries)

## End(Not run)

sofa documentation built on Jan. 4, 2018, 3:43 a.m.