Add context parameter to corpusQuery

Resolves #11

Change-Id: Ifbe1867ed3110a1c37c9f65db418d456629da270
diff --git a/R/KorAPQuery.R b/R/KorAPQuery.R
index 9114c83..b6ed0da 100644
--- a/R/KorAPQuery.R
+++ b/R/KorAPQuery.R
@@ -99,6 +99,12 @@
 #' @param verbose print some info
 #' @param as.df return result as data frame instead of as S4 object?
 #' @param expand logical that decides if `query` and `vc` parameters are expanded to all of their combinations
+#' @param context string that specifies the size of the left and the right context returned in `snippet`
+#'        (provided that `metadataOnly` is set to `false` and that the necessary access right are  met).
+#'        The format of the context size specifcation (e.g. `3-token,3-token`) is described in the [Service: Search GET documentation of the Kustvakt Wiki](https://github.com/KorAP/Kustvakt/wiki/Service:-Search-GET).
+#'        If the parameter is not set, the default context size secification of the KorAP server instance will be used.
+#'        Note that you cannot overrule the maximum context size set in the KorAP server instance,
+#'        as this is typically legally motivated.
 #' @return Depending on the `as.df` parameter, a table or a [KorAPQuery()] object that, among other information, contains the total number of results in `@totalResults`. The resulting object can be used to fetch all query results (with [fetchAll()]) or the next page of results (with [fetchNext()]).
 #' A corresponding URL to be used within a web browser is contained in `@webUIRequestUrl`
 #' Please make sure to check `$collection$rewrites` to see if any unforeseen access rewrites of the query's virtual corpus had to be performed.
@@ -166,7 +172,8 @@
                    accessRewriteFatal = TRUE,
                    verbose = kco@verbose,
                    expand = length(vc) != length(query),
-          as.df = FALSE) {
+          as.df = FALSE,
+          context = NULL) {
   if (length(query) > 1 || length(vc) > 1) {
     grid <- if (expand) expand_grid(query=query, vc=vc) else tibble(query=query, vc=vc)
     purrr::pmap(grid, function(query, vc, ...)
@@ -180,6 +187,7 @@
       request <-
         paste0('?q=',
                url_encode(enc2utf8(query)),
+               ifelse (!metadataOnly && ! is.null(context) && context !=  '', paste0('&context=', url_encode(enc2utf8(context))), ''),
                ifelse (vc != '', paste0('&cq=', url_encode(enc2utf8(vc))), ''), '&ql=', ql)
       webUIRequestUrl <- paste0(kco@KorAPUrl, request)
       requestUrl <- paste0(
diff --git a/man/KorAPQuery-class.Rd b/man/KorAPQuery-class.Rd
index 97000de..ebeb5c7 100644
--- a/man/KorAPQuery-class.Rd
+++ b/man/KorAPQuery-class.Rd
@@ -50,7 +50,8 @@
   accessRewriteFatal = TRUE,
   verbose = kco@verbose,
   expand = length(vc) != length(query),
-  as.df = FALSE
+  as.df = FALSE,
+  context = NULL
 )
 
 \S4method{fetchNext}{KorAPQuery}(
@@ -140,6 +141,13 @@
 
 \item{as.df}{return result as data frame instead of as S4 object?}
 
+\item{context}{string that specifies the size of the left and the right context returned in \code{snippet}
+(provided that \code{metadataOnly} is set to \code{false} and that the necessary access right are  met).
+The format of the context size specifcation (e.g. \verb{3-token,3-token}) is described in the \href{https://github.com/KorAP/Kustvakt/wiki/Service:-Search-GET}{Service: Search GET documentation of the Kustvakt Wiki}.
+If the parameter is not set, the default context size secification of the KorAP server instance will be used.
+Note that you cannot overrule the maximum context size set in the KorAP server instance,
+as this is typically legally motivated.}
+
 \item{kqo}{object obtained from \code{\link[=corpusQuery]{corpusQuery()}}}
 
 \item{offset}{start offset for query results to fetch}