## 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]")
#
# # 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',
# limit = 5)
# ## End(Not run)
Run the code above in your browser using DataLab